Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

how to access drop down list in into my code

$
0
0
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();
       }


Viewing all articles
Browse latest Browse all 23244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>