Hi, I am trying to get the drop down list from a gridview. I am getting error Object reference not set to an instance of an object. I think that I am using the index to locate the row then use findcontrol to determine the control and get its value. Not sure what goes wrong. appreciate your help bob protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { //Only change the GV row to edit mode ((GridView)sender).EditIndex = e.NewEditIndex; callFunctionToFillCombo3(e.NewEditIndex); // passing selectedIndex to populate the combo LoadGridView(); } protected void callFunctionToFillCombo3( int selectedRowIndex) { string Sql = "select countryId,country from country"; string conString = WebConfigurationManager.ConnectionStrings["conStrFtree"].ConnectionString; SqlDataAdapter dad = new SqlDataAdapter(Sql, conString); DataSet dtblCategories = new DataSet(); dad.Fill(dtblCategories); // find control GridViewRow gvr = GridView1.Rows[selectedRowIndex]; // specify the row being edited DropDownList ddlCountry = (DropDownList)gvr.FindControl("ddlCountry"); ddlCountry.DataValueField = "countryId"; ddlCountry.DataTextField = "country"; ddlCountry.DataSource = dtblCategories; ddlCountry.DataBind(); }
↧
how to access drop down list in into my code
↧