Click here to Skip to main content
14,424,386 members
Rate this:
Please Sign up or sign in to vote.
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.

 <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 20:18pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

<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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100