动态生成的textbox怎么获取值? 单击button2得到textbox的值
TableRowtr;TableCelltc;protectedvoidPage_Load(objectsender,EventArgse){if(IsPostBack)...
TableRow tr;
TableCell tc;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
tr = new TableRow();
tc = new TableCell();
tc.Controls.Add(new LiteralControl("借据号"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl("金额(万元)"));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int tdNum = ViewState["tdNum"] == null ? 1 : Convert.ToInt16(ViewState["tdNum"]) + 1;
ViewState["tdNum"] = tdNum;
for (int i = 1; i <= tdNum; i++)
{
tr = new TableRow();
tc = new TableCell();
//tc.Text = "新增的行" + i;
TextBox t = new TextBox();
t.ID = "t" + i.ToString();
t.Text = "add" + i.ToString();
tc.Controls.Add(t);
tr.Cells.Add(tc);
TextBox tt = new TextBox();
tt.ID = "td" + i.ToString();
tt.Text = "ad" + i.ToString();
tc.Controls.Add(tt);
tr.Cells.Add(tc);
Table1.Controls.Add(tr);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
foreach (Control c in Table1.Controls)
{
if (c is TextBox)
{
Label1.Text = "success";
}
}
} 展开
TableCell tc;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
tr = new TableRow();
tc = new TableCell();
tc.Controls.Add(new LiteralControl("借据号"));
tr.Cells.Add(tc);
tc = new TableCell();
tc.Controls.Add(new LiteralControl("金额(万元)"));
tr.Cells.Add(tc);
Table1.Rows.Add(tr);
}
}
protected void Button1_Click(object sender, EventArgs e)
{
int tdNum = ViewState["tdNum"] == null ? 1 : Convert.ToInt16(ViewState["tdNum"]) + 1;
ViewState["tdNum"] = tdNum;
for (int i = 1; i <= tdNum; i++)
{
tr = new TableRow();
tc = new TableCell();
//tc.Text = "新增的行" + i;
TextBox t = new TextBox();
t.ID = "t" + i.ToString();
t.Text = "add" + i.ToString();
tc.Controls.Add(t);
tr.Cells.Add(tc);
TextBox tt = new TextBox();
tt.ID = "td" + i.ToString();
tt.Text = "ad" + i.ToString();
tc.Controls.Add(tt);
tr.Cells.Add(tc);
Table1.Controls.Add(tr);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
foreach (Control c in Table1.Controls)
{
if (c is TextBox)
{
Label1.Text = "success";
}
}
} 展开
4个回答
展开全部
用jQuery或者js很容易搞定的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
代码如下:
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["tdNum"] == null)
{
return;
}
int num = Convert.ToInt32(ViewState["tdNum"]);
for (int i = 1; i <= num; i++)
{
if (Request.Form["t" + i] != null)
{
Label1.Text += Request.Form["t" + i].ToString();
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["tdNum"] == null)
{
return;
}
int num = Convert.ToInt32(ViewState["tdNum"]);
for (int i = 1; i <= num; i++)
{
if (Request.Form["t" + i] != null)
{
Label1.Text += Request.Form["t" + i].ToString();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
protected void Button2_Click(object sender, EventArgs e)
{
if (ViewState["tdNum"] == null)
{
return;
}
int num = Convert.ToInt32(ViewState["tdNum"]);
for (int i = 1; i <= num; i++)
{
if (Request.Form["t" + i] != null)
{
Label1.Text += Request.Form["t" + i].ToString();
}
}
}
{
if (ViewState["tdNum"] == null)
{
return;
}
int num = Convert.ToInt32(ViewState["tdNum"]);
for (int i = 1; i <= num; i++)
{
if (Request.Form["t" + i] != null)
{
Label1.Text += Request.Form["t" + i].ToString();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询