<%@ Page Language="C#" Debug="true" %> <script runat="server"> void Button1_OnClick(object sender, EventArgs e) { int numrows; int numcells; int i = 0; int j = 0; int row = 0; HtmlTableRow r; HtmlTableCell c; // Generate rows and cells numrows = Convert.ToInt32(Select1.Value); numcells = Convert.ToInt32(Select2.Value); for(j = 0;j <= numrows-1; j++) { r = new HtmlTableRow(); if(row % 2 != 0) { r.BgColor = "Gainsboro"; } row++; for(i = 0 ;i <= numcells-1; i++) { c = new HtmlTableCell(); c.Controls.Add(new LiteralControl("row " + j + ", cell " + i)); r.Cells.Add(c); } Table1.Rows.Add(r); } } </script> <html> <head> </head> <body> <form runat="server"> Table rows: <select id="Select1" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> Table cells: <select id="Select2" runat="server"> <option Value="1">1</option> <option Value="2">2</option> <option Value="3">3</option> <option Value="4">4</option> <option Value="5">5</option> </select> <input id="Button1" type="button" OnServerClick="Button1_OnClick" value="Button" runat="server" /> <hr /> <table id="Table1" CellPadding="5" CellSpacing="0" Border="1" runat="server" /> </form> </body> </html>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท