Click here to Skip to main content
15,913,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys

Am loading a dropdownlist...this the code behind aspx page
public void loadDDlClinicName()
        {
            if (!Page.IsPostBack)
            {
                systemBusinessLayer = new BusinessLayer();

                ArrayList clinicList = new ArrayList();
                clinicList = systemBusinessLayer.getClinics();

                ddlClinicName.DataSource = clinicList;
                ddlClinicName.DataTextField = "ClinicName";
                ddlClinicName.DataValueField = "ClinicRefNumber";
                ddlClinicName.DataBind();
                ddlClinicName.Items.Insert(0, ".:Select Clinic:.");
            }
        }

Now code in my BusinessLayer

public ArrayList getClinics()
        {
            using (SqlConnection con = new SqlConnection(ConnString))
            {
                SqlCommand cmd = new SqlCommand("procGetClinics", con);
                cmd.CommandType = CommandType.StoredProcedure;

                
                ArrayList clinicList = new ArrayList();

                try
                {
                    con.Open();
                    SqlDataReader read = cmd.ExecuteReader();
                    while (read.Read())
                    {
                        ClsClinic clinics = new ClsClinic(Convert.ToString(read["ClinicName"]), Convert.ToString(read["ClinicRefNr"]));
                        clinicList.Add(clinics);

                    }
                    read.Close();

                }
                catch (Exception exp)
                {
                    throw new ApplicationException(exp.Message);
                }

                return clinicList;
            }
        }

No i get the error saying "Object reference not set to an instance of an object."
in this line " ddlClinicName.DataSource = clinicList;" but i can see that the values are inside the "clinicList"
Posted
Updated 12-Oct-11 23:33pm
v4
Comments
hitech_s 13-Oct-11 5:35am    
put breakpoint and debug it you will get the solution

That's because it isn't complaining about the reference to clinicList. It's complaining that ddlClinicName is null, instead.

Look through your code - you will find you have not assigned the variable.
 
Share this answer
 
Comments
Espen Harlinn 12-Oct-11 14:52pm    
Nicely spotted!
your clinicList is NULL.
 
Share this answer
 
Since you are saying that clinicList contains values
check whether this ddlClinicName may be null
check the id once .
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900