
Navigator : Home > Tutorials > Controls Tutorials > ...
Table Web server control in ASP.NET 2.0 (VB.NET)
The Table Web server control allows you to create server-programmable tables on ASP.NET pages. This tutorial will show you how to use Table Web server control in ASP.NET 2.0 and C#.
The Table Web server control allows you to create server-programmable tables on ASP.NET pages. The TableRow and TableCell Web server controls provide a way to display the actual content for the Table control. The Table control builds up a table by adding TableRows to the Rows collection of the table, and TableCells to the Cells collection of the row. You can add content to a table cell by adding controls to the Controls collection of the cell.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim numrows As Integer Dim numcells As Integer Dim i As Integer Dim j As Integer Dim r As TableRow Dim c As TableCell ' Generate rows and cells numrows = CInt(DropDown1.SelectedItem.Value) numcells = CInt(DropDown2.SelectedItem.Value) For j = 0 To numrows - 1
r = New TableRow() For i = 0 To numcells - 1
c = New TableCell() c.Controls.Add(New LiteralControl("row " & j & ", cell " & i)) r.Cells.Add(c) Next i Table1.Rows.Add(r) Next j End Sub |
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
The front end .aspx page looks something like this:
<body>
<form id="Form1" runat=server> <fieldset>
<legend>Table Example</legend> <asp:Table id="Table1" Font-Names="Verdana" Font-Size="8pt" CellPadding=5 CellSpacing=0 BorderColor="black" BorderWidth="1" Gridlines="Both" runat="server"/>
<p> Table rows: <asp:DropDownList id=DropDown1 runat="server"> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> </asp:DropDownList>
<br> Table cells: <asp:DropDownList id=DropDown2 runat="server"> <asp:ListItem Value="1">1</asp:ListItem> <asp:ListItem Value="2">2</asp:ListItem> <asp:ListItem Value="3">3</asp:ListItem> <asp:ListItem Value="4">4</asp:ListItem> </asp:DropDownList>
<p> <asp:button ID="Button1" Text="Generate Table" runat=server/> </fieldset> </form>
</body> |
The flow for the code behind page is as follows
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
Partial Class _Default
Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim numrows As Integer Dim numcells As Integer Dim i As Integer Dim j As Integer Dim r As TableRow Dim c As TableCell ' Generate rows and cells numrows = CInt(DropDown1.SelectedItem.Value) numcells = CInt(DropDown2.SelectedItem.Value) For j = 0 To numrows - 1
r = New TableRow() For i = 0 To numcells - 1
c = New TableCell() c.Controls.Add(New LiteralControl("row " & j & ", cell " & i)) r.Cells.Add(c) Next i Table1.Rows.Add(r) Next j End Sub End Class |
Looking for the C#.NET 2005 Version? Click Here!
Looking for more ASP.NET Tutorials? Click Here!