2012-11-20 27 views
3

我使用的表在asp.net網頁表單表不工作

我想是這樣的:

<div> 
    <asp:Table ID="Table1" runat="server"> 
     <tr> 
      <td> asdf </td> 
      <td> asdf </td> 
     </tr> 
    </asp:Table> 
</div> 

它不工作。

航空自衛隊航空自衛隊錯誤創建控制 - UpdatePanel1System.Web.UI.WebControls.TableRowCollection必須 項目類型爲 'System.Web.UI.WebControls.TableRow'。 'tr'類型爲 'System.Web.UI.HtmlControls.HtmlTableRow'。

回答

3

您正在將ASP.NET服務器端控件與標準HTML混合使用。看看在examples on MSDN

<asp:Table id="Table1" runat="server" 
    CellPadding="10" 
    GridLines="Both" 
    HorizontalAlign="Center"> 
    <asp:TableRow> 
     <asp:TableCell> 
      Row 0, Col 0 
     </asp:TableCell> 
     <asp:TableCell> 
      Row 0, Col 1 
     </asp:TableCell> 
    </asp:TableRow> 
    <asp:TableRow> 
     <asp:TableCell> 
      Row 1, Col 0 
     </asp:TableCell> 
     <asp:TableCell> 
      Row 1, Col 1 
     </asp:TableCell> 
    </asp:TableRow> 
</asp:Table> 

在這種情況下asp:Table直接子標籤asp:TableRow(服務器端控制),而不是tr(HTML標記)。

0

行和單元格必須是asp.net服務器控件版本。

<asp:Table ID="Table1" runat="server"> 
    <asp:TableRow> 
     <asp:TableCell></asp:TableCell> 
    </asp:TableRow> 
</asp:Table> 
0

使用:

  <table ID="Table1" runat="server"> 
        <tr> 
         <td> asdf </td> 
         <td> asdf </td> 
        </tr> 
       </table> 
1

不能使用<asp:Table><tr><td><th>標籤,你會與一個標準的HTML <table>相反,你必須按如下方式使用ASP.NET表標籤:

<asp:Table runat="server"> 
    <asp:TableHeaderRow runat="server"> 
    <asp:TableHeaderCell>Header 1</asp:TableHeaderCell> 
    <asp:TableHeaderCell>Header 2</asp:TableHeaderCell> 
    <asp:TableHeaderCell>Header 3</asp:TableHeaderCell> 
    </asp:TableHeaderRow> 
    <asp:TableRow runat="server"> 
    <asp:TableCell>Value 1</asp:TableCell> 
    <asp:TableCell>Value 2</asp:TableCell> 
    <asp:TableCell>Value 3</asp:TableCell> 
    </asp:TableRow> 
</asp:Table>