Thursday, 5 September 2013

How to select item from dropdown list?

How to select item from dropdown list?

I have a drop-down list inside a Gridview:
ASPX:
<ItemTemplate>
<asp:DropDownList ID="status" runat="server"
onselectedindexchanged="status_SelectedIndexChanged"
ondatabinding="status_DataBinding" ondatabound="status_DataBound">
<asp:ListItem>-select-</asp:ListItem>
<asp:ListItem>Winner</asp:ListItem>
<asp:ListItem>Blocked</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
I added my code to fill the DB, with values from page, when I select an
item from the list. However, it inserted the first item " - select- ",
even though I selected a different item from the list. How can I solve
this issue ?
Code:
protected void Open_Click(object sender, EventArgs e)
{
DropDownList DDL =new DropDownList();
for (int i = 0; i < Data.Rows.Count; i++)
{
DDL = (DropDownList)Data.Rows[i].FindControl("status");
}
LinkButton linl = sender as LinkButton;
fb_ID = linl.CommandName;
fbgame.Updatestatus(fb_ID, false,DDL.SelectedIndex.ToString() );
Data.DataSource = fbgame.GetAll();
Data.DataBind();
}

No comments:

Post a Comment