populating dropdownlist when the grid in editmode
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();
}
}
}