当前位置:网站首页>ASP动态创建表格 Table
ASP动态创建表格 Table
2022-06-29 21:33:00 【八十八老】
新建web窗体 Table
添加Table控件
设置Table属性(向Table对象添加行使用Rows属性,向TableRow对象添加单元格使用Cells属性)

在aspx.cs中添加以下代码实现动态创建
protected void Page_Load(object sender, EventArgs e)
{
string[] name = {
"妹妹","哥哥"};
string[] number = {
"201924111", "201924112" };
for (int i= 1; i<=2; i++)
{
TableRow row = new TableRow();//建立一个行对象
TableCell cellNumber = new TableCell(); //建立第一个单元格对象
TableCell cellName = new TableCell();
TableCell cellInput = new TableCell();
cellNumber.Text = number[i - 1];
cellName.Text = name[i - 1];
TextBox txtInput = new TextBox();//建立一个文本框对象
cellInput.Controls.Add(txtInput);//添加文本框对象到第三个单元格中
row.Cells.Add(cellNumber);//添加第一个单元格到行对象
row.Cells.Add(cellName);
row.Cells.Add(cellInput);
tblScore.Rows.Add(row);//添加行对象到表格对象
}
}
aspx完整代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Table.aspx.cs" Inherits="Chap2_Table" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="tblScore" runat="server">
<asp:TableRow runat="server">
<asp:TableCell runat="server">学号</asp:TableCell>
<asp:TableCell runat="server">姓名</asp:TableCell>
<asp:TableCell runat="server">成绩</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
aspx.cs完整代码
using System;
using System.Web.UI.WebControls;
public partial class Chap2_Table : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] name = {
"妹妹","哥哥"};
string[] number = {
"201924111", "201924112" };
for (int i= 1; i<=2; i++)
{
TableRow row = new TableRow();//建立一个行对象
TableCell cellNumber = new TableCell(); //建立第一个单元格对象
TableCell cellName = new TableCell();
TableCell cellInput = new TableCell();
cellNumber.Text = number[i - 1];
cellName.Text = name[i - 1];
TextBox txtInput = new TextBox();//建立一个文本框对象
cellInput.Controls.Add(txtInput);//添加文本框对象到第三个单元格中
row.Cells.Add(cellNumber);//添加第一个单元格到行对象
row.Cells.Add(cellName);
row.Cells.Add(cellInput);
tblScore.Rows.Add(row);//添加行对象到表格对象
}
}
}
边栏推荐
- How to prepare samples for application of color coated steel sealing plates to BS 476-3?
- Motianlun "high availability architecture" dry goods document sharing (including 124 Oracle, MySQL and PG materials)
- 数字密码锁verilog设计+仿真+上板验证
- Bs-gx-017 online examination management system based on SSM
- About Effect Size
- Writing a makefile for a golang project
- [advanced ROS] Lecture 3 ROS file system and distributed communication
- verilog实现DDS波形发生器模块,可实现频率、相位可调,三种波形
- If the evaluation conclusion of waiting insurance is poor, does it mean that waiting insurance has been done in vain?
- BUAA OO unit 4 HW16 unit 4 Summary and course review
猜你喜欢

Threejs basic introduction

Bs-gx-017 online examination management system based on SSM

Summary of document level symbols under different systems

Visual analysis and display effect of summer data

Viewing technological changes through Huawei Corps (V): smart Park

Knowledge distilling learning notes

Résumé du projet de petite bibliothèque

不同系统下的文件层级符号小结

什么是 SYN 洪水攻击?如何防护?

leetcode:238. Product of arrays other than itself
随机推荐
Golang operation etcd
Autodesk Revit 2023 software installation package download and installation tutorial
leetcode:370. 区间加法
My creation anniversary
Résumé du projet de petite bibliothèque
leetcode:307. Area and retrieval - array modifiable
彩涂钢板密封板申请BS 476-3如何备样?
Goahead translation - Active Server Pages
PostgreSQL每周新闻—6月22日
Weibo comments on high availability and high performance computing architecture
Houdini graphic notes: VAT (3.0) import ue4/5 setup wizard [official document translation]
企业实施MES系统的关键点详解
Calibration, correction and world coordinate calculation of binocular stereo vision camera (openCV)
Huawei cloud AOM version 2.0 release
What is unique about MES system?
Use of golang gopsutil Library: process and system resource monitoring (CPU, memory, disk, etc.)
CORDIC based Signal Processor desgn
MES系统究竟有何独特之处?
状态管理 利用Session限制页面访问 只有通过登录验证SessionLogin.aspx才能访问Session.aspx
尚硅谷实时数据仓库项目(阿里云实时数仓)