谁能告诉我如何对 GridView BoundField 对象进行子串化?
到目前为止,我尝试了这一点,但没有奏效。谢谢你。
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# ChopString((string)Eval("description")) %>'></asp:Label>
</ItemTemplate>
谁能告诉我如何对 GridView BoundField 对象进行子串化?
到目前为止,我尝试了这一点,但没有奏效。谢谢你。
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# ChopString((string)Eval("description")) %>'></asp:Label>
</ItemTemplate>
您需要使用子字符串。
Eval("description").ToString().Substring(0,60)
我相信这就是你所需要的。
它说当前上下文中不存在名称“ChopString”
确保您的ChopString
方法在页面的代码隐藏中受到保护或公开。
或许正如之前的用户所说,这些可能不是 ASP.NET 功能?
ChopString
不是内置函数。制作你自己的:
ASPX 代码隐藏
例子:
protected string ChopString(string val)
{
//Check that val is a valid candidate for Substring, i.e. check for nulls, appropriate length, etc
//...
//...
string returnVal = val.Substring(0,60); //Return first 60 chars
return returnVal;
}
Eval("description").ToString().Substring(0, 60);