Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day, I have this Simple Gridview using Eval

<asp:TemplateField HeaderText = "Quantity Delivered" SortExpression="TotalQDelivered">
                <ItemTemplate>

                 <asp:Label ID="lblQuantityDelivered"  runat="server" Text='<%#Eval("TotalQDelivered") %>' />
                        
                </ItemTemplate>
                </asp:TemplateField>



C#
if (e.Row.RowType == DataControlRowType.DataRow)
            {
              
               int TotalQuantity= 0;
                TotalQuantity  += Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "TotalQDelivered"));
               
            }
 if (e.Row.RowType == DataControlRowType.Footer)
            {
                Label lblamount = (Label)e.Row.FindControl("lblTotal");
 lblamount.text =  TotalQuantity.ToString();

             }

// I get this Error Object cannot be cast from DBNull to other types. 
// I must Say that some of the rows are null in the Gridview, 


//How do i ignore the null values so that the rows with values can be calculated..

thanks for wonderful time..
Posted

1 solution

You can look at this article and you will know how to avoid the null error.
http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx[^]
 
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