2011-11-29 60 views
0

所以,我很難解碼VB GridView中的文本。目前,我有以下代碼:Gridview中的VB.NET HTML解碼

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound 
    For Each cell As TableCell In e.Row.Cells 
     For Each ctrl As Control In cell.Controls 
      If TypeOf ctrl Is TextBox Then 
       Dim txtControl As TextBox = DirectCast(ctrl, TextBox) 
       txtControl.Text = Server.HtmlDecode(txtControl.Text) 
      End If 
     Next 
    Next 
End Sub 

但在「視圖」模式下的文本仍然是HTML編碼,而在「編輯」模式下,它們被解碼。

我該如何得到它,以便在兩種模式下解碼?

回答

0

您可以使用此:

If e.Row.RowIndex = Me.Gridview1.EditIndex Then 
'Edit Mode 

Else 
'Not edit mode 

End If 

要確定你是在編輯模式下,設置文本之前。