<html>
<head>
<title>Table Control Example</title>
<link rel = "stylesheet" href = "/shared/netdemos.css">
<script language = "C#" runat = "server">
void Page_Load ( object src, EventArgs e ) {
// generate rows and cells
int rowCnt = int.Parse ( DropDown1.SelectedItem.Value );
int cellCnt = int.Parse ( DropDown2.SelectedItem.Value );
for ( int j = 1; j <= rowCnt; j++ ) {
TableRow r = new TableRow ( );
for ( int i = 1; i <= cellCnt; i++ ) {
TableCell c = new TableCell ( );
c.Controls.Add ( new LiteralControl ( "Buy: " ) );
// Mock up a product ID.
string prodID = j + "_" + i;
HyperLink h = new HyperLink ( );
h.Text = j + ":" + i;
h.NavigateUrl = "http://www.microsoft.com/net";
c.Controls.Add ( h );
r.Cells.Add ( c );
}
myTable.Rows.Add ( r );
}
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc -->
<div class="header"><h2>Table Control Example</h2></div>
<!-- #include virtual="~/shared/viewsrc_top.inc" -->
<hr size=1 width=92%>
<div align="center">
<form runat="server">
<p><asp:table id="myTable" cellpadding=5 cellspacing=0 gridlines="Both" runat="server" /></p>
<table cellpadding=3>
<tr>
<td>Table rows:</td>
<td><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:listitem value="5">5</asp:listitem>
</asp:dropdownlist></td>
<td>Table cells:</td>
<td><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:listitem value="5">5</asp:listitem>
</asp:dropdownlist></td></tr>
<tr>
<td colspan=4 align="center"><asp:button text="Generate Table" runat="server" /></td></tr>
</table>
</form>
</div>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>