Need guidence in GridView

Posted by Mahe under ASP.NET on 7/10/2012 | Points: 10 | Views : 898 | 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.

Regards,
Mahe




Responses

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

Up
0
Down
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";
}

http://stackoverflow.com/questions/8383112/set-selected-value-of-dropdown-list-in-gridview-rowediting
<Columns>
<asp:BoundField DataField="fid" HeaderText="fid" />
<asp:BoundField HeaderText="Fname" DataField="fname"/>
<asp:TemplateField HeaderText="rname">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Style="position: relative" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="price" />
<asp:TemplateField HeaderText="Quantity">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Style="position: relative"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="addcart" HeaderText="ADDCART" Text="Button" />
</Columns>

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
//

}

Premalatha
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

Up
0
Down

Login to post response