如何在GridView中设置最大长度 [英] How to set maximum length in a gridview
本文介绍了如何在GridView中设置最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
报价:
索引和长度必须引用字符串中的位置.
参数名称:长度
Index and length must refer to a location within the string.
Parameter name: length
我从Internet获得了以下代码,但是当我应用该代码时,出现了以上错误.
i have got the following code from Internet but when i applied that code i am getting the above error.
<asp:TemplateField>
<HeaderTemplate>
Programme
</HeaderTemplate>
<ItemTemplate>
<%#Eval("ProgrammeName").ToString().Substring(0, 10)%>
</ItemTemplate>
</asp:TemplateField>
推荐答案
尝试确定长度,请检查以下代码.
try to fix the length, check the following code.
<![CDATA[<%# Eval("ProgrammeName").ToString().Substring(0, Math.Min(Eval("ProgrammeName").ToString().Length, 10)) %>]]>
请使用此选项来确保文本长度至少为10个字符.
Use this instead to make sure that text is atleast 10 characters long.
<%#Eval("ProgrammeName").ToString().PadRight(10,' ').Substring(0, 10).Trim() %>
这篇关于如何在GridView中设置最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文