Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
TotalPrice += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem,"PrePie"));

}
else if(e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[7].Text = TotalPrice.ToString();
e.Row.Cells[7].Font.Bold = true;

}
}

What I have tried:

C#
Object cannot be cast from DBNull to other types. how to fix it

Please help
Posted
Updated 12-Dec-16 7:30am

1 solution

You do not say which line produces the error but I am guessing it is:

C#
TotalPrice += Convert.ToDouble(DataBinder.Eval(e.Row.DataItem,"PrePie"));


You cannot assume a value is in the gridview cell, test PrePie has a value before you use it and take appropriate action if it is nul.
 
Share this answer
 
v2
Comments
Member 12857358 13-Dec-16 5:04am    
if PrePie contains a null value then how to assign 0 in it.
Michael_Davies 13-Dec-16 5:46am    
Test PrePie's value if it is NOT null then add it to TotalPrice

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