如何在ASP.NET中将gridview为空时解决索引超出范围的问题 [英] How to solve index out of range when gridview is empty in ASP.NET

查看:57
本文介绍了如何在ASP.NET中将gridview为空时解决索引超出范围的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中使用了一个标签,其文本值为Text ='<%#Container.DataItemIndex + 1%>'



当gridview为空,我得到以下错误:

 索引  范围。必须是非负小于 集合。 
参数名称: index





我知道Label没有不接受0.所以如何解决这个问题?

解决方案

删除标签。试试这个:



 <   asp:TemplateField     HeaderText   =  S否 >  
< ItemTemplate >
<% #Container.DataItemIndex +1 %GT;
< / ItemTemplate >
< / asp:TemplateField >





不需要标签此处


I am using a label in gridview which has a text value as Text='<%#Container.DataItemIndex+1 %>'

When the gridview is empty, I get the following error as

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index



I know that Label doesn't accept 0. So how to solve this problem ??

解决方案

Remove the label.Try this:

<asp:TemplateField HeaderText="S No">
        <ItemTemplate>
           <%#Container.DataItemIndex +1 %>
        </ItemTemplate>
        </asp:TemplateField>



Label is not needed here


这篇关于如何在ASP.NET中将gridview为空时解决索引超出范围的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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