Wednesday, June 20, 2012

How to bind data to a DDL present inside a GridView from Database and retain the selection


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  DropDownList ddlDropDownList = (DropDownList)e.Row.FindControl("ddlDropDownList");
  if (ddlDropDownList != null)
  {
     ddlDropDownList.FindByValue(Convert.ToString(ViewState["selectedvalue"])).Selected = true;    
  }
  }
}

No comments:

Post a Comment