sri divya

sri divya

  • NA
  • 2
  • 2.1k

populating dropdownlist when the grid in editmode

May 20 2014 1:20 PM
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();
}
         }
    }


Answers (1)