Server side HTML table with tbody not compiling in

2019-07-20 22:14发布

问题:

Possible Duplicate:
How to create thead and tbody in ASP.NET Table?

The following HTML does not compile in an ASP.NET Website

<table runat="server" id="tbl1">
  <tbody>
    <tr>
      <td>
      </td>
    </tr>
  </tbody>
</table>

I get this compilation error:

The best overloaded method match for ‘System.Web.UI.HtmlControls.HtmlTableRowCollection.Add(System.Web.UI.HtmlControls.HtmlTableRow)’ has some invalid arguments
  • This error started appearing after I installed VS2012 and .NET 4.5
  • It occurs in both VS2012 and VS2010
  • It appears in ASP.NET Website project template, the code compiles fine in ASP.NET WebApplication project template
  • The error disappears when removing the "runat" attribute OR the "tbody" tag
  • The weird thing is that the project fails to compile but publishes successfully without errors
  • The page renders correctly in the browser
  • If I uninstall VS2012 and .NET 4.5 the same code works again in VS2010

Update:

I'm not sure why this question was closed in the first place, it wasn't a duplicate. Anyway, Microsoft has acknowledged this as a bug and is working on a fix. More info here

回答1:

You might want to try :

  <table id="yourId" runat="server">
     <thead>
         .
         .
         .
     </thead>
      <tbody>
          <tr>
             <td>
             </td>
          </tr>    
            </tbody>
  </table>