Need guidence in GridView

Posted by Mahe under ASP.NET on 7/10/2012 | Points: 10 | Views : 1039 | Status : [Member] | Replies : 3
Hi All,

Please provide me the code for the following senario

- On Selecting of dropdown value, the GridView should get populated accordingly.
- On Selecting of dropdown value which is in the GridView, the other column in the same GridView should change accordingly.
- On Selecting of dropdown value, the other dropdown list should have values accordingly.



Posted by: Premalatha on: 7/10/2012 [Member] Starter | Points: 25

Does these things inside the SelectedIndexChanged event of the DropDownList

First find the row.
Then access the controls and change accordingly.
Pseudo Code

protected void grd_ddlEmp_SelectedIndexChanged(object sender, EventArgs e)
GridView row = ((DropDownList)sender).NamingContainer as GridViewRow;
Label Designation = row.FindControl("id of the designation label") as Label;
Designation.Text = "new Designation Name";
<asp:BoundField DataField="fid" HeaderText="fid" />
<asp:BoundField HeaderText="Fname" DataField="fname"/>
<asp:TemplateField HeaderText="rname">
<asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:BoundField HeaderText="price" />
<asp:TemplateField HeaderText="Quantity">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>
<asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
string restaurantname = DropDownList1.SelectedValue.ToString();
SqlCommand price = new SqlCommand("select price from maintable where rid='" + restaurantname + "'", con);
SqlDataAdapter value_price = new SqlDataAdapter(price);
DataSet ds1 = new DataSet();
value_price.Fill(ds1, "Table");
// I need to show the price according to selection of dropdown list


Software Engineer

Mahe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/11/2012 [Member] [MVP] Gold | Points: 25


Login to post response