Search code examples
c#asp.net.nethtml-tablerunatserver

Error in table when adding runat=server


I have a html table in my ASPX page and would like to use it in code-behind for some processing. The table is shown as below:

<table class="hovertable" id="tblData">
    <tr>
        <th>ID:</th>
        <td colspan="3" style="font-weight: bold">
            <%= Eval("ID") %>
        </td>
    </tr>
    <tr>
        <th>Date:</th>
        <td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
        <th>Amount:</th>
        <td><%# Eval("Amount", "{0:C}") %>
    </tr>
</table>

However, when I add the runat="server" attribute to my table, I am produced with the following error:

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

Any ideas what may be wrong here? Am I missing out anything?


Solution

  • OK guys, I have solved this issue by myself. The problem causing it was because of a <td> not having the corresponding <tr> element. It was something like below:

    <table class="hovertable" id="tblData">
        <tr>
            <th>ID:</th>
            <td colspan="3" style="font-weight: bold">
                <%= Eval("ID") %>
            </td>
        </tr>
        <tr>
            <th>Date:</th>
            <td><%# Eval("Date", "{0:dd-MMM-yyyy}") %></td>
            <th>Amount:</th>
            <td><%# Eval("Amount", "{0:C}") %>
        </tr>
        <td colspan='4'>
           Some data....
        </td>
    </table>