I have a problem. I want to display data from database using drop down list and radio button in the grid view. The idea is, from the grid view user can select value from drop down list and radio button to update their record. So, they didn't need to type the value to update their record. They only need to choose the value and click the update button to save the changes. I have no idea at all how to do this. Please someone help me.
kvprajapati 1,826 Posting Genius Team Colleague
>how to display certain data from database using drop down list in the grid view
Which database product are you using? Please show us your code work.
maria_mj 0 Light Poster
>how to display certain data from database using drop down list in the grid view
Which database product are you using? Please show us your code work.
I am using SQL database. I am using grid view to display the data from the data base. The code of the is:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="pipeline_id" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="company_name" HeaderText="company_name"
SortExpression="company_name" />
<asp:BoundField DataField="project_name" HeaderText="project_name"
SortExpression="project_name" />
<asp:BoundField DataField="gross_profit" HeaderText="gross_profit"
SortExpression="gross_profit" />
<asp:BoundField DataField="project_revenue" HeaderText="project_revenue"
SortExpression="project_revenue" />
<asp:BoundField DataField="category_pipeline" HeaderText="category_pipeline"
SortExpression="category_pipeline" />
<asp:TemplateField HeaderText="status_pipeline"
SortExpression="status_pipeline">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="status_pipeline"
DataValueField="status_pipeline" SelectedValue='<%# Bind("status_pipeline") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("status_pipeline") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="bde_name" HeaderText="bde_name"
SortExpression="bde_name" />
<asp:BoundField DataField="deadline" HeaderText="deadline"
SortExpression="deadline" />
<asp:BoundField DataField="remark" HeaderText="remark"
SortExpression="remark" />
<asp:BoundField DataField="pipeline_id" HeaderText="pipeline_id"
InsertVisible="False" ReadOnly="True" SortExpression="pipeline_id"
Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
SelectCommand="SELECT [status_pipeline] FROM [Pipeline_status]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BDASConnectionString %>"
DeleteCommand="DELETE FROM [Project_Pipeline] WHERE [pipeline_id] = @pipeline_id"
InsertCommand="INSERT INTO [Project_Pipeline] ([company_name], [project_name], [gross_profit], [project_revenue], [category_pipeline], [status_pipeline], [bde_name], [deadline], [remark]) VALUES (@company_name, @project_name, @gross_profit, @project_revenue, @category_pipeline, @status_pipeline, @bde_name, @deadline, @remark)"
SelectCommand="SELECT [company_name], [project_name], [gross_profit], [project_revenue], [category_pipeline], [status_pipeline], [bde_name], [deadline], [remark], [pipeline_id] FROM [Project_Pipeline]"
UpdateCommand="UPDATE [Project_Pipeline] SET [company_name] = @company_name, [project_name] = @project_name, [gross_profit] = @gross_profit, [project_revenue] = @project_revenue, [category_pipeline] = @category_pipeline, [status_pipeline] = @status_pipeline, [bde_name] = @bde_name, [deadline] = @deadline, [remark] = @remark WHERE [pipeline_id] = @pipeline_id">
<DeleteParameters>
<asp:Parameter Name="pipeline_id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="company_name" Type="String" />
<asp:Parameter Name="project_name" Type="String" />
<asp:Parameter Name="gross_profit" Type="Decimal" />
<asp:Parameter Name="project_revenue" Type="Decimal" />
<asp:Parameter Name="category_pipeline" Type="String" />
<asp:Parameter Name="status_pipeline" Type="String" />
<asp:Parameter Name="bde_name" Type="String" />
<asp:Parameter Name="deadline" Type="String" />
<asp:Parameter Name="remark" Type="String" />
<asp:Parameter Name="pipeline_id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="company_name" Type="String" />
<asp:Parameter Name="project_name" Type="String" />
<asp:Parameter Name="gross_profit" Type="Decimal" />
<asp:Parameter Name="project_revenue" Type="Decimal" />
<asp:Parameter Name="category_pipeline" Type="String" />
<asp:Parameter Name="status_pipeline" Type="String" />
<asp:Parameter Name="bde_name" Type="String" />
<asp:Parameter Name="deadline" Type="String" />
<asp:Parameter Name="remark" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
kvprajapati 1,826 Posting Genius Team Colleague
While configure a datasource for GridView, click on Where button to select column name, operator, and control name.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.