I have requirement to bind ASP.Net DropDownList control in EditItemTemplate of GridView.
I preferred the tutorial:
http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTemplate-of-GridView-in-ASPNet.aspx
i have followed same steps just but difference is i have a edit imagebutton with commandname="Edit".Also dropdown needs to be binded from different table(directory) and not the table through whicch grid is binded(details).
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit && GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList DStatusEdit = (DropDownList)e.Row.FindControl("DStatusEdit");
string query = "select distinct status from directory";
SqlCommand cmd = new SqlCommand(query);
DStatusEdit.DataSource = GetData(cmd);
DStatusEdit.DataTextField = "status";
DStatusEdit.DataValueField = "status"; DStatusEdit.DataBind(); //DStatusEdit.Items.Insert(0, new ListItem("--Select--", "0")); //DStatusEdit.Items.FindByValue((e.Row.FindControl("Lstat") as Label).Text).Selected =true;
}
the page is running but when i click edit image button the dropdwn shows but no data in dropdown binded it is empty.
My gridview is inside update panel.
How can i achieve this?
Should dropdownlist in my case be binded inside rowcommand and how?