Search code examples
htmlasp.nethtml-tablerepeater

Repeater and Html table


Browser returns me this problem: CS1502: The best overloaded method match for 'System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)' has some invalid arguments

I have no idea about the problem. I use this repeater object and table like this all the time. and it works fine with this way. But now it gives an error. Where is the problem? thanks!!

design side

<table id="myTable" runat="server" class="table table-striped table-hover">
                    <asp:Repeater ID="lstBanks" runat="server" OnItemDataBound="lstBanks_ItemDataBound"
                        OnItemCommand="lstBanks_ItemCommand">
                        <ItemTemplate>
                            <tr>
                                <td>
                                    SSSs
                                    <asp:HiddenField ID="hfID" Value='<%#Eval("ID") %>' runat="server" />
                                </td>
                                <td>
                                    SSS
                                </td>
                                <td>
                                    SSS
                                </td>
                                <td>
                                    SSS
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>

Solution

  • You shouldn't have the runat="server" attribute on your <table>, element, since you're building raw HTML for it. It's parsing that into memory as a strongly-typed table, then getting confused when you try and add a Repeater instead of a tr. Just remove that attribute and I believe it should work.

    Although that all said, you might want to switch over to GridView. Each has advantages, and admittedly I prefer MVC because I can write HTML similar to what you're doing. But in WebForms, a GridView is likely preferable.