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

I'm getting error "object reference not set to an instance of an object".
I know the reason for this error if assigned DataSet is empty at that time we face this type of issue's but my DataSet Having data. Then why it's showing this error....

my code is like this

C#
protected void gvMaterials_RowDataBound(object sender, GridViewRowEventArgs e)
{ 

       if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState ==       DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
       {
            Label lblMaterial_Id = (Label)e.Row.FindControl("lblMaterial_Id");
            DataList dlQuantities = (DataList)e.Row.FindControl("dlQuantities");
            DataSet ds = obj.Get_Planned_Material_Qty(Proj_Code,lblMaterial_Id.Text);
                                 
            dlQuantities.DataSource = ds;            
            dlQuantities.DataBind();
                
       }
}

This is my code i'm facing pblm on highlited line, but my DataSet having 18 rows.
What's the reason it's showing that error....

Can Any one help me to resolve this issue....
Posted
Comments
Karthik Harve 13-Mar-13 6:06am    
dataset is having rows, that is fine, have you checked, does the object "dlQuantities" is null or not ?
Naveen.Sanagasetti 13-Mar-13 6:08am    
Can u plz explain eloborate about "dlQuantities" is null or not....
Karthik Harve 13-Mar-13 6:12am    
you are finding the control "dlQuantities", does that controls exists ?, if that controls not exists, that object becomes null and if you are trying to access null object, then this error will occur. just put the break point at that line, and place mouse pointer over the object, you can see whether it is null or not.
Naveen.Sanagasetti 13-Mar-13 6:12am    
dlQuantities is NULL
Karthik Harve 13-Mar-13 6:13am    
so, that is the reason for error.

Either ds or dlQuantities is an invalid reference.
 
Share this answer
 
v2
Comments
Naveen.Sanagasetti 13-Mar-13 6:10am    
Can u plz explain eloborate about "dlQuantities" is an invalid reference....
This error occurs when you try and access a property or attribute of an object that itself is null.
Debug and step through your code to figure out what the problem could be.
 
Share this answer
 
you shoud provide dataset like ds.tables[0]. it may work!!!!
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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