-1

In DevExpress AspxGridview control binding

protected void ASPxGridView1_DataBinding(object sender, EventArgs e) 
{
     // in this event I want to reach LabelText and modify it as "text =Server.HtmlDecode(text);" 
}

Bu I can not reach LabelText. I tried to find a solution but never found.

Please help me. I am stuck ....

<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>
Bibhu
  • 4,053
  • 4
  • 33
  • 63
abkaplan1
  • 1
  • 1
  • 6

1 Answers1

1

You can simple do it in the markup as below:

Text='<%# Server.HtmlEncode( (string) Eval( "text" ) ) %>' />

Refer:
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

If you want it to access the label control and then use the grid HtmlRowCreated event then you can modify the text.. Refer below link...

Find controls in a dataitemtemplate of ASPxGridView column
ASPxGridView - How to find a control in grid DataItemTemplate - using DataBoundEvent event

example

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
Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
  • follow the reference link and try to use databound event if you think it will work then.. – Niranjan Singh Sep 12 '13 at 14:33
  • I reach elements in ASPxGridView1_HtmlRowPrepared but htmldecode does not run == text = Server.HtmlDecode(text); no decode – abkaplan1 Sep 12 '13 at 15:14
  • Outside of gridview I tested it and I use it and it decodes. Bu when I try to decode in gridview it does not decode.... Why ??? – abkaplan1 Sep 12 '13 at 15:34
  • Finally !.. if I use "asp:Label" decodes runs... bu if I use "dx:ASPxLabel" decodes does no run !.... SOLUTION FOUND – abkaplan1 Sep 12 '13 at 15:45