Search code examples
asp.netdata-bindingbindingrepeater

repeater is not binding when the value starts with "<"


I'm using repeater to bind the data from the stored procedure. It is correctly binding data most of the time, but i'm facing a problem when it is not working as expected when the result column value starts with "<",

Repeater Code:

<asp:Repeater ID="repeter1" runat="server">
   <HeaderTemplate>
      <table style="table-layout: fixed; width:100%;" >
   </HeaderTemplate>
   <ItemTemplate>
         <tr>
           <th>Column 1</th>
           <th>Column 2</th>
           <th>Column 3</th>
         </tr>
         <tr>
           <td>
              <asp:Label ID="lbl1" runat="server"><%#DataBinder.Eval(Container.DataItem, "column1")%></asp:Label></td>
           <td>
              <asp:Label ID="lbl2" runat="server"><%#DataBinder.Eval(Container.DataItem, "column2")%></asp:Label></td>
           <td>
              <asp:Label ID="lbl3" runat="server"><%#DataBinder.Eval(Container.DataItem, "column3")%></asp:Label></td>
         </tr>
    </ItemTemplate>
    <FooterTemplate>
      </table>
    </FooterTemplate>
</asp:Repeater>

Suppose if we take "column3", it is not binding at all when the output value starts with "<" or ">" like that, (it seems like special characters).

Can Someone please let me know how to resolve this one.

Thanks in Advance!


Solution

  • Wrap it with Server.HtmlEncode() like this:

    <asp:Label ID="lbl3" runat="server"><%# Server.HtmlEncode(Eval("column3").ToString())%></asp:Label>