摘要:如何取得GridView中HyperLinkField的文字
GridView中若加入了HyperLinkField該如何將其內容值取出或是修改呢?
以下用一小段程式來說明:
本程式是在做GridView1中HyperLink欄位的判別,
當欄位字串長度大於10時,只印出前10個字元,並將後面看不到的字元以"..."代替
01
Protected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
02
03
Dim strSrc As String
04
Dim strNew As String
05
strNew = ""
06
07
If (e.Row.RowType = DataControlRowType.DataRow) Then
08
'取得gridview中hyperlink控制項的文字
09
strSrc = CType(e.Row.Cells(1).Controls(0), HyperLink).Text
10
'當HyperLink的字串內容大於10的時候,取得前10個字元,並加入"..."
11
If Len(strSrc) >= 10 Then
12
strNew = Left(strSrc, 10) & "..."
13
CType(e.Row.Cells(1).Controls(0), HyperLink).Text = strNew
14
End If
15
End If
16
End Sub
Protected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 02
03
Dim strSrc As String 04
Dim strNew As String 05
strNew = "" 06
07
If (e.Row.RowType = DataControlRowType.DataRow) Then 08
'取得gridview中hyperlink控制項的文字 09
strSrc = CType(e.Row.Cells(1).Controls(0), HyperLink).Text 10
'當HyperLink的字串內容大於10的時候,取得前10個字元,並加入"..." 11
If Len(strSrc) >= 10 Then 12
strNew = Left(strSrc, 10) & "..." 13
CType(e.Row.Cells(1).Controls(0), HyperLink).Text = strNew 14
End If 15
End If 16
End Sub
Protected