ASP.Net/Asp Control/Table — различия между версиями

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

Версия 15:30, 26 мая 2010

Add asp:tablecell

<%@ 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>



Add row to asp:table

<%@ 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>
        <B>Product</B>
        </asp:tablecell>
        <asp:tablecell>
        <B>Quantity</B>
        </asp:tablecell>
    </asp:tablerow>
</asp:table>
<BR><BR>
Product:
<BR>
<asp:textbox 
    id="txtProduct" 
    runat=server 
/>    
<BR>
Quantity:<BR>
<asp:textbox 
    id="txtQuantity" 
    runat=server 
/>    
<BR>
<asp:button 
id="butSubmit"
text="OK"
onclick="SubmitBtn_Click" 
runat="server"
/>
</form>
</BODY>
</HTML>



asp:table with static data

<%@ 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>
        <B>Product</B>
        </asp:tablecell>
        <asp:tablecell>
        <B>Quantity</B>
        </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>



Layout controls in an asp:Table

<%@ 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>
   <h1>Display Control Example</h1>
   <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"/>
                  <br>
                  <asp:textbox id="PanelTB" text="TextBox inside Panel" runat="Server"/>
               </asp:panel>
            </asp:tablecell>
         </asp:tablerow>
      </asp:table>
   </form>
</body>
</html>



Table Footer Row

<%@ 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">
    <div id="container">
    <h2>Accessible Table Example</h2>
<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>
    </div>
    </form>
</body>
</html>