挑战你,table中的 textbox如何遍历?

FIRSTVIP 2005-09-22 04:41:28
aspx代码:
<asp:Table id="Table2" runat="server"></asp:Table>
<asp:Button id="Button1" runat="server" Text="提交插入记录" Width="112px"></asp:Button>
cs代码
private void Page_Load(object sender, System.EventArgs e)
{
while(dr.Read())
{

TextBox txt=new TextBox();
txt.ID=dr[0].ToString();
TableRow tr = new TableRow();
TableCell tc = new TableCell();


tc.Controls.Add(txt);
tr.Cells.Add(tc);
this.Table2.Rows.Add(tr);

}
}

private void Button1_Click(object sender, System.EventArgs e)
{
我该如何遍历TextBox ??
}
...全文
238 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuwenzhuo 2005-09-22
  • 打赏
  • 举报
回复
如果你的页面内只有表格内有TextBox的话,这样更快:
foreach(Control c in this.Controls)
{
if(typeof(c)==TextBox)
{;your operation;}
}
}
chenqianliang 2005-09-22
  • 打赏
  • 举报
回复
楼上的已经给出代码了
wjq19801212 2005-09-22
  • 打赏
  • 举报
回复
foreach(TableRow tr in this.Table2.Rows)
{
foreach(TableCell tc in tr.Cells)
{
foreach(Control c in tc.Controls)
{
if(typeof(c)==TextBox)
{;your operation;}
}
}
}
NekChan 2005-09-22
  • 打赏
  • 举报
回复
利用容器。
zzhtd 2005-09-22
  • 打赏
  • 举报
回复
for(int i=0;i<Table1.Controls.Count;i++)
{
if(Table1.Controls[i].GetType().ToString())=="System.Web.UI.WebControls.TextBox")
{
//取值  
   ((System.Web.UI.WebControls.TextBox)Table1.Controls[i]).Text;
}
}

62,244

社区成员

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

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

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

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