Question

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="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

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top