在DevExpress AspxGridview中控制绑定
protected void ASPxGridView1_DataBinding(object sender, EventArgs e)
{
// in this event I want to reach LabelText and modify it as "text =Server.HtmlDecode(text);"
}
我无法访问LabelText。我试图找到一个解决方案,但从未找到过。
请帮帮我。我被困了....
<dx:GridViewDataColumn VisibleIndex="0" Width="100%" CellStyle-HorizontalAlign="Left" CellStyle-VerticalAlign="Middle" Caption=" "> <EditFormSettings Visible="False" /> <DataItemTemplate> <table class="table_white"> <tr> <td style="text-align:left">
<asp:Label ID="LabelName" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</td> </tr> <tr> <td style="text-align:left"> <asp:Label ID="LabelText" runat="server" Text='<%#Eval("text") %>'></asp:Label>
</td> </tr> <tr> <td style="text-align:left">
<hr style="border: 1px solid #CCCCCC" />
</td> </tr> </table> </DataItemTemplate>
<CellStyle HorizontalAlign="Center" VerticalAlign="Middle"></CellStyle> </dx:GridViewDataColumn>
答案 0 :(得分:1)
您可以在标记中简单地执行以下操作:
Text='<%# Server.HtmlEncode( (string) Eval( "text" ) ) %>' />
参见:
How to use HtmlEncode with TemplateFields, Data Binding, and a GridView
<%: %> Syntax for HTML Encoding in a repeater
HtmlEncode and Bind Description
ASP.NET "special" tags
如果您希望它访问标签控件然后使用网格HtmlRowCreated
事件,那么您可以修改文本..请参阅以下链接...
Find controls in a dataitemtemplate of ASPxGridView column
ASPxGridView - How to find a control in grid DataItemTemplate - using DataBoundEvent event
例如
Protected Sub ASPxGridView1_DataBound(sender As Object, e As System.EventArgs) Handles ASPxGridView1.DataBound
Dim y As Integer = 0
Dim x As Integer = Me.ASPxGridView1.VisibleRowCount - 1
For y = 0 To x
Dim ilabel As ASPxLabel = CType(Me.ASPxGridView1.FindRowCellTemplateControl(y, Nothing, "lblCategory"), ASPxLabel)
If ASPxGridView1.GetRowValues(y, "CategoryName").ToString() = "Confections" Then
ilabel.ClientVisible = False
End If
Next
End Sub