.. the exception message is "Databinding methods such as Eval(), XPat..." /> .. the exception message is "Databinding methods such as Eval(), XPat..." /> .. the exception message is "Databinding methods such as Eval(), XPat..."/>

problem with repeater

160 views Asked by At

while i am running this code an exception is occuring at <%Eval("Firstname")%>.. the exception message is "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control." what to do..my code is as follows

<div>This is repeater
         <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
         <HeaderTemplate>
         <table>
         <tr>
            <th>FirstName</th>
            <th>LastName</th>
            <th>City</th>
          </tr>
         </HeaderTemplate>
         <ItemTemplate>
         <tr>
         <td><% Eval("FirstName")%></td>
         <td><% Eval("LastName")%></td>
         <td><% Eval("City")%></td>
         </tr>
         </ItemTemplate>
         <FooterTemplate>
         </table>
         </FooterTemplate>
         </asp:Repeater>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
             ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
             SelectCommand="SELECT * FROM [Employees]">
         </asp:SqlDataSource>
    </div>
2

There are 2 answers

1
dustyhoppe On BEST ANSWER

I think you are missing the # symbol

try:

<%# Eval("FirstName") %>
2
PHeiberg On

To have the data emitted through databinding you should use the data-binding expression syntax

<%# Eval("FieldName")%>