ASP.Net/Asp Control/Table

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Add asp:tablecell

   <source lang="csharp">

<%@ Page Language=VB Debug=true %> <script runat=server> Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

   Dim MyTable = New Table
   Dim NumRows as Integer
   Dim NumColumns as Integer
   For NumRows = 1 to 3
       Dim TheRow = New TableRow
       For NumColumns = 1 to 4
           Dim TheCell = New TableCell
           TheCell.Text = NumRows & "," & NumColumns
           TheRow.Cells.Add(TheCell)
       Next
       MyTable.Rows.Add(TheRow)
   Next
   frmMyPage.Controls.Add(MyTable)

End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Creating an HTML Table Using the Table Control</TITLE> </HEAD> <BODY LEFTMARGIN="40"> <form id="frmMyPage" runat="server"> </form> </BODY> </HTML>

      </source>
   
  


Add row to asp:table

   <source lang="csharp">

<%@ Page Language=VB Debug=true %> <script runat=server> Sub SubmitBtn_Click(Sender As Object, E As EventArgs)

   Dim TheRow = New TableRow
   Dim TheProduct = New TableCell
   Dim TheQuantity = New TableCell
   TheProduct.Text = txtProduct.Text
   TheQuantity.Text = txtQuantity.Text
   TheRow.Cells.Add(TheProduct)
   TheRow.Cells.Add(TheQuantity)
   Table1.Rows.Add(TheRow)

End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Creating an HTML Table Using the Table Control</TITLE> </HEAD> <BODY LEFTMARGIN="40"> <form runat="server"> <asp:table

   id="table1" 
   runat="server"

>

   <asp:tablerow>
       <asp:tablecell>
       Product
       </asp:tablecell>
       <asp:tablecell>
       Quantity
       </asp:tablecell>
   </asp:tablerow>

</asp:table>

Product:
<asp:textbox

   id="txtProduct" 
   runat=server 

/>
Quantity:
<asp:textbox

   id="txtQuantity" 
   runat=server 

/>
<asp:button id="butSubmit" text="OK" onclick="SubmitBtn_Click" runat="server" /> </form> </BODY> </HTML>

      </source>
   
  


asp:table with static data

   <source lang="csharp">

<%@ Page Language=VB Debug=true %> <HTML> <HEAD> <TITLE>Creating an HTML Table Using the Table Control</TITLE> </HEAD> <BODY LEFTMARGIN="40"> <form runat="server"> <asp:table

   id="table1" 
   runat="server"
   cellpadding=5 
   cellspacing=1
   gridlines="Both"

>

   <asp:tablerow>
       <asp:tablecell>
       Product
       </asp:tablecell>
       <asp:tablecell>
       Quantity
       </asp:tablecell>
   </asp:tablerow>
   <asp:tablerow>
       <asp:tablecell>
       Socks
       </asp:tablecell>
       <asp:tablecell>
       5
       </asp:tablecell>
   </asp:tablerow>
   <asp:tablerow>
       <asp:tablecell>
       Shirts
       </asp:tablecell>
       <asp:tablecell>
       52
       </asp:tablecell>
   </asp:tablerow>
</asp:table>

</form> </BODY> </HTML>

      </source>
   
  


Layout controls in an asp:Table

   <source lang="csharp">

<%@ Page Language="vb" %> <html> <head>

  <title>Display Control Example</title>
  <script runat="server">
     Sub Page_Load()
        MyLabel.Text = "New Label"
        MyImage.ImageUrl = "http://www.nfex.ru/style/logo.png"
     End Sub
  </script>

</head> <body>

Display Control Example

  <form runat="server">
     <asp:table id="MyTable" border="1" cellpadding="5" cellspacing="0" runat="server">
        <asp:tablerow runat="server">
           <asp:tablecell colspan="2" runat="server">
              Table Control
           </asp:tablecell>
        </asp:tablerow>
        <asp:tablerow runat="server">
           <asp:tablecell runat="server">
              Label Control:
           </asp:tablecell>
           <asp:tablecell runat="server">
              <asp:label id="MyLabel" 
                 text="This is a Label Control"
                 borderstyle="solid" 
                 bordercolor="Green" 
                 runat="Server" />
           </asp:tablecell>
        </asp:tablerow>
        <asp:tablerow runat="server">
           <asp:tablecell runat="server">
              Image Control:
           </asp:tablecell>
           <asp:tablecell runat="server">
              <asp:image id="MyImage" 
                 imageurl="image.jpg" 
                 runat="Server" />
           </asp:tablecell>
        </asp:tablerow>
        <asp:tablerow runat="server">
           <asp:tablecell runat="server">
              Panel Control:
           </asp:tablecell>
           <asp:tablecell runat="server">
              <asp:panel id="MyPanel"
                 backcolor="lightblue"
                 bordercolor="Green"
                 borderwidth=1 
                 runat="server">            
                 <asp:label id="MyLabel2" 
                    text="Static Text within the Panel" 
                    runat="Server"/>
                 
<asp:textbox id="PanelTB" text="TextBox inside Panel" runat="Server"/> </asp:panel> </asp:tablecell> </asp:tablerow> </asp:table> </form>

</body> </html>

      </source>
   
  


Table Footer Row

   <source lang="csharp">

<%@ Page Language="C#"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

   <title>Accessible Table Example</title>
   <style type="text/css">
     table { border-collapse: collapse; width: 30em; margin-top: 1em;}
     caption { font-size: 1.1 em; font-weight: bold; margin: 1em; }
     th, td { padding: 0.1em 1em; }
     th { text-align: left; font-weight: bold; background-color: #FFFF80; 
          border-top: 3px solid #a5a5a5; border-bottom: 3px solid #a5a5a5;
          border-right: 1px solid #cccccc; border-left: 1px solid #cccccc;}
     td { border: 1px solid #cccccc; }
     tfoot { background-color: #FFFFC0; border-top: 2px solid #a5a5a5; font-style: italic;}
   </style>

</head> <body>

   <form id="form1" runat="server">

Accessible Table Example

<asp:Table id="tabMarkup" runat="server"

    Caption="Timing Results for Running Test"
    CaptionAlign="Top">
  <asp:TableHeaderRow >
     <asp:TableHeaderCell Text="Name" ID="headName" />
     <asp:TableHeaderCell Text="First Trial" ID="headFirst" />
     <asp:TableHeaderCell Text="Second Trial" ID="headSecond" />
  </asp:TableHeaderRow>
  <asp:TableRow>
     <asp:TableCell Text="Fred" AssociatedHeaderCellID="headName" />
     <asp:TableCell Text="10.5" AssociatedHeaderCellID="headFirst" />
     <asp:TableCell Text="36.5" AssociatedHeaderCellID="headSecond" />
  </asp:TableRow>
  <asp:TableRow>
      <asp:TableCell Text="Sue" AssociatedHeaderCellID="headName" />
     <asp:TableCell Text="45.3" AssociatedHeaderCellID="headFirst" />
     <asp:TableCell Text="16.5" AssociatedHeaderCellID="headSecond" />
  </asp:TableRow>
  <asp:TableFooterRow TableSection="TableFooter">
      <asp:TableCell Text="Average" AssociatedHeaderCellID="headName" />
     <asp:TableCell Text="27.9" AssociatedHeaderCellID="headFirst" />
     <asp:TableCell Text="10.0" AssociatedHeaderCellID="headSecond" />
  </asp:TableFooterRow>        

</asp:Table>

   </form>

</body> </html>

</source>