⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webform1.aspx.cs

📁 C#2005 实例源代码
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TableTest
{
	/// <summary>
	/// WebForm1 的摘要说明。
	/// </summary>
	public partial class WebForm1 : System.Web.UI.Page
	{
	
		//动态生成Table控件
		protected void Page_Load(object sender, System.EventArgs e)
		{
			//变量
			int numRows = Convert.ToInt32(Request.QueryString["rows"]);	//行数
			int numCells = Convert.ToInt32(Request.QueryString["cols"]);//列数

			Table1.BorderWidth=1;
			Table1.BorderColor=System.Drawing.Color.Black;

			//循环Table1生成多行
			for (int i=0; i<numRows; i++) 
			{
				TableRow r = new TableRow();	//得到一个TableRow对象r
				//循环生成r中的多个单元格
				for (int j=0; j<numCells; j++) 
				{
					TableCell c = new TableCell();//得到一个TableCell对象c
					c.Text=Table1.Rows.Count.ToString() + "," + j.ToString();
					r.Cells.Add(c);				//将c添加到r中
				}
				Table1.Rows.Add(r);	//将r天加到Table1中
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		/// <summary>
		/// 添加一行
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Button1_Click(object sender, System.EventArgs e)
		{
			int numCells = Convert.ToInt32(Request.QueryString["cols"]);//列数

			TableRow r = new TableRow();	//得到一个TableRow对象r
			//循环生成r中的多个单元格
			for (int j=0; j<numCells; j++) 
			{
				TableCell c = new TableCell();//得到一个TableCell对象c
				c.Text=Table1.Rows.Count.ToString() + "," + j.ToString();
				r.Cells.Add(c);				//将c添加到r中
			}
			Table1.Rows.Add(r);	//将r天加到Table1中
			Response.Redirect("WebForm1.aspx?rows="+Table1.Rows.Count+"&cols="+Table1.Rows[0].Cells.Count);
		}

		/// <summary>
		/// 添加一列
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void Button2_Click(object sender, System.EventArgs e)
		{
			int numRows = Convert.ToInt32(Request.QueryString["rows"]);	//行数

			//循环Table1生成多行
			for (int i=0; i<numRows; i++) 
			{
				TableRow r = Table1.Rows[i];	//得到一个TableRow对象r
				//循环生成r中的多个单元格
				TableCell c = new TableCell();//得到一个TableCell对象c
				c.Text=i.ToString() + "," + r.Cells.Count.ToString();
				r.Cells.Add(c);				//将c添加到r中
			}
			Response.Redirect("WebForm1.aspx?rows="+Table1.Rows.Count+"&cols="+Table1.Rows[0].Cells.Count);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -