I want to populate my dropdownlist when my gv is in editmode,i want the corresponding ID of the record to be displayed in my dropdownlist .Iam specifying the dropdownlist outside the gridview .Thanks.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DataRowView drv = e.Row.DataItem as DataRowView;
DropDownList ddlnric = (DropDownList)e.Row.FindControl("ddlnric");
string query = "select DISTINCT ecode from Employeesms";
SqlCommand cmd = new SqlCommand(query);
ddlnric.DataSource = GetData(cmd);
ddlnric.DataTextField = "ecode";
ddlnric.DataValueField = "ecode";
ddlnric.DataBind();
ddlnric.SelectedValue = drv["lblcode"].ToString();
}
}
}
Populating dropdownlist when the grid in editmode
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Munesh SharmaRank #174 · 13.9K reputationPosted May 20, 2014, 8:47 PM EDT