I have requirement to bind ASP.Net DropDownList control in EditItemTemplate of GridView. I have a edit imagebutton with commandname=\"Edit\"also dropdown needs to be binded
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) {
using (SqlConnection con = new SqlConnection(ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT GatePassNo,PurposeOfVisit FROM VisitorList"))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
DropDownList ddlpurposeofvisit = (DropDownList)e.Row.FindControl("ddlpurposeofvisit");
ddlpurposeofvisit.DataSource = cmd.ExecuteReader();
ddlpurposeofvisit.DataTextField = "PurposeOfVisit";
ddlpurposeofvisit.DataValueField = "GatePassNo";
ddlpurposeofvisit.DataBind();
con.Close();
}
}
}