<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeBehind="Webtable.aspx.cs" Inherits="WebTableDemo.Webtable" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Xonclick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebTableDemo
{
public partial class Webtable : System.Web.UI.Page
{
public void GetTable(int number)
{
int num = number;
TableRow tr;
TableCell td;
for (int i = 1; i <= num; i++)
{
tr = new TableRow();
for (int j = 1; j <= i; j++)
{
td = new TableCell();
td.Text = i + "*" + j + "=" + i * j;
tr.Cells.Add(td);
}
Table1.Rows.Add(tr);
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetTable(9);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Table1.Rows.Clear();
int number = Convert.ToInt32(TextBox1.Text);
GetTable(number);
}
}
}