解决方案 »
- 视频直播的问题、
- |zyciis| IIS创建网站和应用程序池后,如何设置他为主目录的执行权限为“纯脚本”还有他的“应用程序名”
- 求一个Sql 语句 在entity framework 中的写法
- 怎么在cs里面获得DropDownList text的值
- 天热裸体请教,有灭有人做过电子优惠卷的?Graphics Graphics Graphics
- 一个存储过程操作两个表,报错(在线等)
- 如何获取datagrid中某一列绑定的DataField
- 读取XML文件
- 请问一个显示的问题,我的笔记本是1028*768的分辩率我的台式机也是1024*768的分辩率,为什么在笔记本上显示是正常的呢?
- 两端通过Adsl,一端能否访问另一端的数据库
- 用FindControl在页面找控件的问题
- WMV文件无法播放???在线等
定义一个静态变量存储 TableCell tc = new TableCell();
static List<TableCell> listc = new static List<TableCell>();
点击 Button1_Click时先将 tc 加到 listc里
之后再从 listc循环里读取添加到页面
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Collections.Generic;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class development : System.Web.UI.Page
{
static List<TableCell> listc = new List<TableCell>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
ViewState["i"] = 0;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
TableCell tc=new TableCell();
tc.ID="tc" + ViewState["i"].ToString();
TextBox tx = new TextBox();
tx.ID = "tx" + ViewState["i"].ToString();
tx.Text = "Hello";
tc.Controls.Add(tx);
listc.Add(tc);
for (int j = 0; j < listc.Count; j++)
{
TableRow tr=new TableRow();
tr.ID="tr"+ViewState["i"].ToString();
tr.Cells.Add(listc[j]);
t1.Controls.Add(tr);
}
//TableCell tc = new TableCell();
//tc.ID = "tc" + ViewState["i"].ToString(); //TextBox tx = new TextBox();
//tx.ID = "tx" + ViewState["i"].ToString();
//tx.Text = "Hello";
//tc.Controls.Add(tx); //tc.Width = Unit.Pixel(100); //TableRow tr = new TableRow();
//tr.ID = "tr" + ViewState["i"].ToString();
//tr.Controls.Add(tc); //t1.Rows.Add(tr);
}
protected void Button2_Click(object sender, EventArgs e)
{
for (int j = 0; j < Convert.ToInt32(ViewState["i"]); j++)
{
TextBox2.Text += (t1.FindControl("tx" + j) as TextBox).Text;
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
ViewState["i"] = 0;
listc = new List<TableCell>(); }
}
这样试试