Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NullException Error when binding to a dropdown

Status
Not open for further replies.

citizenzen

Programmer
Jun 28, 2007
102
0
0
US
Hello.

I am receiving an error when I bind to a dropdownlist.

Object reference not set to an instance of an object. at modifyProgramming.fillLibrary() in c:\Inetpub\ 313

I have a similar page which functions fine, but I don't see where my error lies on this page. How can there be an error with the datasource?

Code:
 private void fillLibrary()
    {
        string showu = ConfigurationManager.ConnectionStrings["RevisedTapeLibrary"].ConnectionString;
        SqlConnection libconn = new SqlConnection(showu);
        SqlCommand libcom = new SqlCommand("select * from view_chooseLibraryTG", libconn);
        libconn.Open();

        DropDownList newlibr = new DropDownList();
        DataTable libdt = new DataTable();

           foreach (GridViewRow bu in EditProgramGV.Rows)
            {
                CheckBox rt = (CheckBox)bu.FindControl("selectRowChk");
                if (rt != null && rt.Checked)
                {
                    newlibr = (DropDownList)EditProgramGV.FindControl("libdrop");
                    SqlDataAdapter ji = new SqlDataAdapter(libcom);
                    ji.Fill(libdt);
                    newlibr.DataSource = libdt;
                    newlibr.DataTextField = "Library";
                    newlibr.DataValueField = "ID";
                    newlibr.DataBind();
                    newlibr.AutoPostBack = true;
                }
            }
        
        libconn.Close();
    }
 
My guess would be that the line
Code:
 newlibr = (DropDownList)EditProgramGV.FindControl("libdrop");
isn't finding the control.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top