“Substring”一个GridView BoundField对象

谁能告诉我如何对GridView BoundField对象进行子串?

我到目前为止尝试过这个并没有奏效。 谢谢。

 <asp:Label ID="Label1" runat="server" Text=''>  

你需要使用子串。

  Eval("description").ToString().Substring(0,60) 

我相信这就是你所需要的。

它说当前上下文中不存在名称’ChopString’

确保您的ChopString方法在页面的代码隐藏中受到保护或公开。

也许正如之前的用户所说,这些可能不是ASP.NET的function?

ChopString不是内置函数。 做你自己的:

ASPX Codebehind

例:

 protected string ChopString(string val) { //Check that val is a valid candidate for Substring, ie check for nulls, appropriate length, etc //... //... string returnVal = val.Substring(0,60); //Return first 60 chars return returnVal; } 
 Eval("description").ToString().Substring(0, 60);