Object reference not set to an instance of an object.
how can i set that?
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2009, 6:46 AM EST
✓ Accepted answer0
When you get that error while debugging, you need to look at the data to see what is not set. I assume that mydg is not set, but it would help to know for sure. So assuming that mydg is not set, then obviously the line:
DataGrid mydg = (DataGrid)cart.FindControl("dg");
Is not working. You need to use try/catch blocks whenever there is a possible problem such as this. Assuming that mydg is not set, you need to at least diagnose and fix that.
0
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 17, 2009, 6:30 AM EST
0
Friend,
this can be happening because of your Session["Cart"] may be returning null.
check if Session["Cart"] is Null ???
because it can be the cause of problem .
if (Session["Cart"] !=null) {
//All your Code Here
} else { Response.Write("Cart is Null"); }
if my answer helps you then "check Do you like this answer check box" please :)
if still having problem then let me know .
or
you can send me your project Files(Zip) with database at [email protected]
jingeRank #2,527 · 554 reputationPosted Nov 17, 2009, 2:40 PM EST
0
@ kirtan,
If the datatable is null, then such exception can not be happened. It makes sense to assign the DataSource to null. The only possible cause is the datagrid is a null reference.
Sam HobbsRank #107 · 20.5K reputationPosted Nov 17, 2009, 6:46 AM EST
Kirtan PatelRank #292 · 8.6K reputationPosted Nov 17, 2009, 6:30 AM EST
this can be happening because of your Session["Cart"] may be returning null.
check if Session["Cart"] is Null ???
because it can be the cause of problem .
if (Session["Cart"] !=null)
{
//All your Code Here
}
else
{
Response.Write("Cart is Null");
}
if my answer helps you then "check Do you like this answer check box" please :)
if still having problem then let me know .
or
you can send me your project Files(Zip) with database at [email protected]
i will resolve your problem :)
jingeRank #2,527 · 554 reputationPosted Nov 17, 2009, 2:40 PM EST
If the datatable is null, then such exception can not be happened. It makes sense to assign the DataSource to null. The only possible cause is the datagrid is a null reference.
Bahar Jalali165 reputationPosted Nov 17, 2009, 10:22 PM EST
all ideas were good and help me
i change the datagrid with a gridview and i forgot change it in the code
but by your help i understand that
thanks for advance