.aspx 文件:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="t1.aspx.cs" Inherits="t1" %>

<!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 method="post" runat="server">   

<asp:Label style="Z-INDEX: 101; LEFT: 41px; ; TOP: 33px" runat="server">Asp.Net Table控件动态生成表格操作实例</asp:Label> &nbsp;   

<asp:Table style="Z-INDEX: 104; LEFT: 35px; ; TOP: 89px" runat="server"   GridLines="Both" BorderColor="#FFC080" BorderStyle="Dotted" BorderWidth="1px" CellPadding="0" CellSpacing="0" Height="153px" Width="344px">   

</asp:Table>       

</form>

</body>

</html>

.cs文件:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

public partial class t1 : System.Web.UI.Page

{    

        protected void Page_Load(object sender, EventArgs e)    

              {        

                         int I, J;        

                         for (I = 0; I < 6; I++)//6行        

                            {            

                                 TableRow Row = new TableRow();            

                                    for (J = 0; J < 4; J++)//4列  

                                     {

                                            TableCell Cell = new TableCell();  

                                            Cell.Text = "Column=" + J.ToString();  

                                            if (J == 3)//第4列添加按钮控件  

                                                  {

                                                       Button btnA = new Button();

                                                       btnA.Text = "Column=3";  

                                                       Cell.Controls.Add(btnA);

                                                  }   

                                    Row.Cells.Add(Cell);            

                                   }            

                           Table1.Rows.Add(Row);    

     }

    }

}

 

效果图:

在.net中利用Web控件Table动态生成表格

相关文章:

  • 2021-08-18
  • 2021-09-17
  • 2022-02-11
  • 2022-12-23
  • 2021-12-13
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-09
  • 2021-09-13
  • 2021-08-16
  • 2021-11-30
  • 2021-07-19
  • 2021-09-13
  • 2021-11-02
相关资源
相似解决方案