当前位置:网站首页>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);//添加行对象到表格对象
}
}
}
边栏推荐
- Hardware development notes (VIII): basic process of hardware development, making a USB to RS232 module (VII): creating a basic dip component (crystal oscillator) package and associating the principle
- Writing a makefile for a golang project
- 企业实施MES系统的关键点详解
- Golang operation etcd
- [advanced ROS] Lecture 3 ROS file system and distributed communication
- Vipshop Keyword Search API interface (item_search- search vipshop commodity API interface by keyword), vipshop API interface
- leetcode:724. 寻找数组的中心下标
- 亚马逊商品详情API接口-(item_get-获得AMAZON商品详情接口),亚马逊详情API接口
- 唯品会商品详情API接口(item_get-获得唯品会商品详情接口),唯品会详情API接口
- leetcode:370. Interval addition
猜你喜欢

Structure the fifth operation of the actual camp module

Recruit | DBA Data Engineer every week with an annual salary of 35+. Dream of Kyushu and bright stars!

Résumé du projet de petite bibliothèque

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

STM32 minimum system construction (schematic diagram)

Report delivery engineer

Reading notes on how to connect the network - Web server request and response (V)

About Effect Size


STL tutorial 6-deque, stack, queue, list container
随机推荐
Calibration, correction and world coordinate calculation of binocular stereo vision camera (openCV)
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
小型图书馆项目总结
[advanced ROS chapter] lesson 2 custom header and source file encapsulation
yolov6训练自己的数据记录+yolov5对比测试
leetcode:238. 除自身以外数组的乘积
Use of golang gopsutil Library: process and system resource monitoring (CPU, memory, disk, etc.)
Flutter BottomNavigationBar带有页面切换示例
Topic39——78. 子集
Rsync method of establishing multi directory module
Getting started with completabilefuture
What is a SYN Flood attack? How to protect?
Top ten questions for senior Performance Test Engineer
Sophon CE community edition goes online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
Bs-gx-017 online examination management system based on SSM
不同系统下的文件层级符号小结
STM32 and gd32 notes
直播预告 | PostgreSQL 内核解读系列第一讲:PostgreSQL 系统概述
PostgreSQL每周新聞—6月22日
leetcode:307. Area and retrieval - array modifiable