Binding Data to server controls in asp:repeater
I would like to have a repeater control bound to method and display the result as a list of linkbuttons, but I can't get by head around it. This is what I've tried:
In the asp page I have:
<asp:Repeater ID="resultCountRepeater" runat="server" Visible="false" >
<ItemTemplate>
<asp:LinkButton ID=开发者_StackOverflow中文版"userResultCount" runat="server" OnClick="userResultCount_Click" Text="<%# DataBinder.Eval(Container.DataItem,"Text") %>" >
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
And in the code behind:
List<ListItem> resultCountList = new List<ListItem>();
foreach (ISearchEngine oneEng in engines)
{
ListItem item = new ListItem();
item.Text = oneEng.ObectName();
item.Value = Convert.ToString(oneEng.PageCount(searchWords, townId));
resultCountList.Add(item);
}
resultCountRepeater.DataSource = resultCountList;
resultCountRepeater.DataBind();
Unfortunately this is giving me a compile error: The server tag is not well formed.
Any ideas what it wrong?
Thanks
Use single quotes to dynamically set properties.
<asp:LinkButton ID="userResultCount" runat="server" OnClick="userResultCount_Click" Text="<%# DataBinder.Eval(Container.DataItem,"Text") %>" ></asp:LinkButton>
Should be
<asp:LinkButton ID="userResultCount" runat="server" OnClick="userResultCount_Click" Text='<%# DataBinder.Eval(Container.DataItem,"Text") %>' ></asp:LinkButton>
精彩评论