关于HtmlTable的,高分奉送哦~

Pandahu880225 2010-11-12 03:18:48
具体如下:

我在aspx.cs页面中New了两个HtmlTabel A和B,现在我想在A中某一个单元格里将B添加进去,请问这样要如何添加啊???
请各位写个示范代码,感激不敬啊!!!
...全文
114 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fellowcheng 2010-11-12
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApp {
public partial class HtmlTableSample : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
NewTableA();
form1.Controls.Add(A);
}

HtmlTable A;
int aRows = 4;
int aCols = 4;
private void NewTableA() {
A = new HtmlTable();
for (int j = 0; j < aRows; j++) {

// Create a new row and add it to the Rows collection.
HtmlTableRow row = new HtmlTableRow();

// Provide a different background color for alternating rows.
if (j % 2 == 1)
row.BgColor = "Gray";

// Iterate through the cells of a row.
for (int i = 0; i < aCols; i++) {
// Create a new cell and add it to the HtmlTableRow
// Cells collection.
HtmlTableCell cell = new HtmlTableCell();
if (i == 0 && j == 0) {
cell.Controls.Add(NewTableB());
}
else {
cell.Controls.Add(new LiteralControl("row " +
j.ToString() +
", cell " +
i.ToString()));
}
row.Cells.Add(cell);
}

// Add the row to the HtmlTable Rows collection.
A.Controls.Add(row);
}

}


private HtmlTable NewTableB() {
int bRows = 2;
int bCols = 2;
HtmlTable B = new HtmlTable();
for (int j = 0; j < bRows; j++) {

// Create a new row and add it to the Rows collection.
HtmlTableRow row = new HtmlTableRow();

// Provide a different background color for alternating rows.
if (j % 2 == 1)
row.BgColor = "Blue";

// Iterate through the cells of a row.
for (int i = 0; i < bCols; i++) {
// Create a new cell and add it to the HtmlTableRow
// Cells collection.
HtmlTableCell cell = new HtmlTableCell();
cell.Controls.Add(new LiteralControl("row " +
j.ToString() +
", cell " +
i.ToString()));
row.Cells.Add(cell);
}

// Add the row to the HtmlTable Rows collection.
B.Controls.Add(row);
}
return B;
}
}
}
Pandahu880225 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sprc_lcl 的回复:]
C# code
HtmlTable A = new HtmlTable();

HtmlTableRow htr = new HtmlTableRow();
HtmlTableCell htc = new HtmlTableCell();

HtmlTable B = new HtmlTable();

……
[/Quote]添加其他控件的话也可以这样操作吗???
ToMakeLove 2010-11-12
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sprc_lcl 的回复:]
C# code
HtmlTable A = new HtmlTable();

HtmlTableRow htr = new HtmlTableRow();
HtmlTableCell htc = new HtmlTableCell();

HtmlTable B = new HtmlTable();

……
[/Quote]
我用过,不过一般不怎么用得到
dalmeeme 2010-11-12
  • 打赏
  • 举报
回复
A.Rows[3].Cells[2].Controls.Add(B);//表格A的第3行第2列单元格中添加B
sprc_lcl 2010-11-12
  • 打赏
  • 举报
回复
        HtmlTable A = new HtmlTable();

HtmlTableRow htr = new HtmlTableRow();
HtmlTableCell htc = new HtmlTableCell();

HtmlTable B = new HtmlTable();

htc.Controls.Add(B);
htr.Cells.Add(htc);

A.Rows.Add(htr);
随着通信电子技术的迅速发展,信息技术给家居行业产生了深远的影响,家居环境的智能化监控已经成为智能家居的一个重要的发展方向。人们逐渐对自己的生活提出一种更高的要求,他们需要一种智能化、可交互,并且融合现代创新科技的产品来改善他们的生活环境,使他们生活更加安全、舒适、便捷、智能。本文根据智能家居的发展背景和研究现状,并且从实用性和可行性角度出发,研究设计了一种基于STM32单片机的智能家居系统。该系统由一个多功能综合的技术系统组成,各个多功能子系统间具有协同配合能力。基于STM32单片机实现的功能子系统包括:智能温度检测,智能湿度检测,智能烟雾/火灾检测智能检测,无线传输,人机交互机构,风扇调节,报警模块。 整个系统分为前端51单片机采集板和后端STM32单片机接收板。 采集板使用DHT11温湿度传感器、MQ烟雾传感器完成室内家居环境的采集。然后通过nRFL24L01将采集到的数据发送给后端。接收板使用LCD1602完成数据显示、使用蜂鸣器模块报警,使用风扇驱动模块调节室内家居环境。本文完成了智能家居控制系统前端、后端软硬件的设计,使用Altium designer绘制了电路原理图,使用Keil C完成了51单片机和STM32单片机的编程与调试。 最后,对本文设计的基于STM32的智能家居控制系统进行部署调试。试验结果表明,该系统可成功应用在智能家居环境检测调节和火灾安全防护的领域,可提高家居生活智能化水平。

62,271

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧