Click here to Skip to main content
14,881,921 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using dropdown inside gridview. The dropdown shows item list.
Here I want on selection of item name label display rate for that item.
Please let me know if I need to bind rate label with database actually i have bind dropdown and label both by database then gridview display all item name in dropdown and rate in label but i want when user select item name from dropdown then label rate display respected item rate.

my aspx page is.

XML
 <asp:GridView ID="grd1" runat="server" DataSourceID="SqlDataSource1"
     AutoGenerateColumns="False" DataKeyNames="Product_Id" OnRowDataBound="grd1_RowDataBound">
     <Columns>
         <asp:TemplateField HeaderText="Product_Name" SortExpression="Product_Name">
             <ItemTemplate>
                 <asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" DataSourceID="SqlDataSource2"
                     DataTextField="Product_Name" Width="100px" DataValueField="Product_Id" AppendDataBoundItems="true" SelectedValue='<%# Bind("Product_ID") %>'>
                 </asp:DropDownList>
             </ItemTemplate>
         </asp:TemplateField>
         <asp:BoundField DataField="Product_Rate" SortExpression="Product_Rate" HeaderText="Product_Rate"/>
         <asp:TemplateField HeaderText="Product_Quantity" SortExpression="Product_Quantity">
         <EditItemTemplate>
         <asp:TextBox ID="txtQty" runat="server"/>
         </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Product_Amount" SortExpression="Product_Amount">
         <ItemTemplate>
         <asp:Label ID="lblAmount" runat="server" />
         </ItemTemplate>
         </asp:TemplateField>
     </Columns>
 </asp:GridView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
     ConnectionString="<%$ ConnectionStrings:chalk_hillConnectionString %>"
     SelectCommand="SELECT [Product_Id],[Product_Name], [Product_Rate]  FROM [Product_Detail]">
 </asp:SqlDataSource>
         <asp:SqlDataSource ID="SqlDataSource2" runat="server"
     ConnectionString="<%$ ConnectionStrings:chalk_hillConnectionString %>"
     SelectCommand="SELECT [Product_Id],[Product_Name] FROM [Product_Detail]">
 </asp:SqlDataSource>
 <tr><td align="center">
  <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="Submit"/>
  <asp:Button ID="Button1" runat="server" Text="Clear" OnClick="Clear"/>
  </td></tr>
 </table>
</center>
Posted
Updated 25-Oct-10 19:18pm
v2

1 solution

<div width="" height=""><pre lang="xml">&lt;asp:GridView ID=&quot;grd1&quot; runat=&quot;server&quot; DataSourceID=&quot;SqlDataSource1&quot;
AutoGenerateColumns=&quot;False&quot; DataKeyNames=&quot;Product_Id&quot; OnRowDataBound=&quot;grd1_RowDataBound&quot;&gt;
&lt;Columns&gt;
&lt;asp:TemplateField HeaderText=&quot;Product_Name&quot; SortExpression=&quot;Product_Name&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:DropDownList ID=&quot;DropDownList1&quot; AutoPostBack=&quot;true&quot; runat=&quot;server&quot; DataSourceID=&quot;SqlDataSource2&quot;
DataTextField=&quot;Product_Name&quot; Width=&quot;100px&quot; DataValueField=&quot;Product_Id&quot; AppendDataBoundItems=&quot;true&quot; SelectedValue=&#39;&lt;%# Bind(&quot;Product_ID&quot;) %&gt;&#39;&gt;
&lt;/asp:DropDownList&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:BoundField DataField=&quot;Product_Rate&quot; SortExpression=&quot;Product_Rate&quot; HeaderText=&quot;Product_Rate&quot;/&gt;
&lt;asp:TemplateField HeaderText=&quot;Product_Quantity&quot; SortExpression=&quot;Product_Quantity&quot;&gt;
&lt;EditItemTemplate&gt;
&lt;asp:TextBox ID=&quot;txtQty&quot; runat=&quot;server&quot;/&gt;
&lt;/EditItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;asp:TemplateField HeaderText=&quot;Product_Amount&quot; SortExpression=&quot;Product_Amount&quot;&gt;
&lt;ItemTemplate&gt;
&lt;asp:Label ID=&quot;lblAmount&quot; runat=&quot;server&quot; /&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
&lt;/Columns&gt;
&lt;/asp:GridView</pre>
></div>

then private void dgvData_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
}

in this event write the code block
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900