2012-06-18 23 views
2

任何人都可以告訴我如何子串一個GridView的BoundField對象嗎?「子串」一個GridView的BoundField對象

我試過這個到目前爲止,它沒有奏效。謝謝。

<ItemTemplate> 
<asp:Label ID="Label1" runat="server" Text='<%# ChopString((string)Eval("description")) %>'></asp:Label> 
</ItemTemplate> 
+0

你有什麼需要走出的字符串?它總是一樣的長度嗎? –

+0

我試過這個,並且不工作:'Text ='<%#Left(Eval(「description」),60)%>''。我需要前60個字符。 – Sam

+0

@TimA'Left'是一個VB.NET函數。 – HackedByChinese

回答

2

您需要使用子。

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

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

+1

有點遲了,我知道,但是謝謝。救了我一些悲傷。 – Robert

2

它說「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; 
} 
相關問題