如何检查Eval是否为空并忽略它RSS [英] How Can I Check if Eval Is Null And Ignore It RSS

查看:58
本文介绍了如何检查Eval是否为空并忽略它RSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天,我使用这个简单的Gridview使用Eval



< asp:TemplateField HeaderText =Quantity DeliveredSortExpression = TotalQDelivered > 
< ItemTemplate>

< asp:Label ID =lblQuantityDeliveredrunat =serverText ='<%#Eval(TotalQDelivered)%>' />

< / ItemTemplate>
< / asp:TemplateField>







  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();

}

// 我得到这个错误对象不能是从DBNull转换为其他类型。
// 我必须说Gridview中的某些行为空,





//如何忽略空值,以便可以计算具有值的行..



感谢您的精彩时间..

解决方案

您可以查看这篇文章,您将了解如何避免空错误。

http://msdn.microsoft.com/en-us/library /2cf62fcy.aspx [ ^

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>




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..

解决方案

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[^]


这篇关于如何检查Eval是否为空并忽略它RSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆