Search code examples
c#asp.netrepeater

unable to bind data to label inside repeater


My code is like this

<asp:Repeater ID="rptEvaluationInfo" runat="server">
<ItemTemplate>
   <asp:Label runat="server" Id="lblCampCode" Text="<%#Eval("CampCode") %>"></asp:Label>

</ItemTemplate>

Everything looks okay to me, But it generates an error in the runtime. When I remove this part

Text="<%#Eval("CampCode") %>" 

error goes. SO I assume the issue is with databind. So I tried an alternative like this

    <asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
    <label><%#Eval("CampCode") %> </label>

</ItemTemplate>

And it also works good. Can any one tell me what is the issue with my first code?

Note: I don't have access to the error message due to the special reasons on my project , that's why I have not posted it here. And I want to use ASP controls itself on the case that's why i haven't gone with my second solution


Solution

  • The problem is with quotes. Currently you have double quotes everywhere, so ASP.NET is not able to parse this. Change outer ones to single quotes like this:

    Text='<%#Eval("CampCode") %>'