Reputation: 1096
I've got a gridview
, with one field
as a dropdownlist
..
I am trying to read the values
inside the dropdownlist
but the first item in the list is always selected
..
This code is inside the gridview:
<asp:TemplateField HeaderText="Bank">
<ItemTemplate>
<asp:DropDownList ID="DropDown" runat="server" OnLoad="dropdownLoad" />
</ItemTemplate>
</asp:TemplateField>
at the backend, i am using the following code:
DropDownList ddl = (DropDownList)GridView1.Rows[0].Cells[7].FindControl("DropDown");
string s1 = ddl.SelectedValue;
What shall I do ?
Upvotes: 1
Views: 1233
Reputation: 420
Try this code..
GridViewRow row = (GridViewRow)((Control)sender).NamingContainer;
DropDownList drp = (DropDownList)row.FindControl("drp");
lbl.Text = drp.SelectedValue;
Upvotes: 2
Reputation: 1
Do not search in a particular cell. Instead i would suggest you to search the dropdown in the row it self.
So the code should be some thing like :
DropDownList ddl = GridView1.Rows[0].FindControl("DropDown") as DropDownList;
cheers.
Upvotes: 0