I am binding a DataTable to a repeater. However when I run my aspx page it is not evaluating the Eval statements and displaying them on the page as
<<%# Eval("Name").ToString() %> Posted by: <<%# Eval("UserName").ToString() %>
<<%# Eval("Name").ToString() %> Posted by: <<%# Eval("UserName").ToString() %>
<<%# Eval("Name").ToString() %> Posted by: <<%# Eval("UserName").ToString() %>
It is also breaking it down to 3 rows. Which is also not what I had expected. I thought it would display as spans normally would
I have taken out the .ToString to check if it was that causing the issue. But it was not.
Below is my Repeater
<asp:Repeater ID="First" runat="server">
<ItemTemplate>
<div class="ItemDiv">
<span class="ItemLeft"></span>
<span class="ItemCentre">
<asp:Label ID="Name" runat="server" Text='<<%# Eval("Name").ToString() %>'></asp:Label>
</span>
<span class="ItemRight">
<asp:Label ID="UserName" runat="server" Text='<<%# Eval("UserName").ToString() %>'></asp:Label>
</span>
</div>
</ItemTemplate>
</asp:Repeater>
The code to bind is the following:
public void dataLoad()
{
DataTable Data = loadData(1,1,1);
if (Data.Rows.Count < 10)
{
// Only populate the data from datatable
First.DataSource = Data;
First.DataBind();
Second.Visible = false;
noData.Visible = true;
}
I have changed some of the names in the above example
In the Debug information I can see that my DataTable is using the correct column names, and that these match my eval statements.
I know I have created this in a rather strange way, from what I have read, and researched online it is more common to use a table rather than Divs/or Spans for this. So I am aware that that may be the problem at its heart.
I cannot see why it would be any different.
Remove the << from your eval statements. It should be:
<div class="ItemDiv">
<span class="ItemLeft"></span>
<span class="ItemCentre">
<asp:Label ID="Name" runat="server" Text='<%# Eval("Name").ToString() %>'></asp:Label>
</span>
<span class="ItemRight">
<asp:Label ID="UserName" runat="server" Text='<%# Eval("UserName").ToString() %>'></asp:Label>
</span>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With