.net如何获取一组TextBox的值啊,

qq9799645 2012-04-19 01:59:56
<asp:TextBox ID="MainProducts1" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts2" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts3" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts4" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts5" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts6" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts7" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts8" runat="server" Height="20px" Width="100px"></asp:TextBox>
怎么样才能获取这此textbox的值,并且存到一个字段里呀?
...全文
436 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
cfanser 2012-04-23
  • 打赏
  • 举报
回复
用控件遍历!如果TextBox是动态增加的用2楼的方法不可取!
xboxeer 2012-04-23
  • 打赏
  • 举报
回复
2楼的靠谱
porschev 2012-04-23
  • 打赏
  • 举报
回复

Page.FindControl()方法可以。。。

遍历控件,判断是否是textbox可以

也可以用JS或Jquery

给TextBox相同的Name,比如:name="txtAbc"


$("[name='txtAbc']").each(function(){
alert($(this).val()); //$(this).val()是每个值
});

EnForGrass 2012-04-23
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
<asp:TextBox ID="MainProducts1" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:TextBox ID="MainProducts2" runat="server" Height="20px" Width="100px"></asp:TextBox>
<asp:T……
[/Quote]
TextBox[] txarray;
然后用Page.FindControl(),取出来放到txarray里
  • 打赏
  • 举报
回复
恩 同意2楼得 这个方法可行
lgk2012 2012-04-23
  • 打赏
  • 举报
回复
遍历指定区域的控件,按类型进行组合处理,打个比方上述的TextBox都在一个Panel里(panel1),即如下处理:

string dynObject=string.Empty;

foreach(Control c in panel1.Controls)
{
if(c.GetType()==typeof(TextBox))
{
dynObject+=string.Format("{0}/",((TextBox)c).Text);
}
}

dynObject即为值集合,格式为(TextBox1/TextBox2....)
Rommel_Gao 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

C# code

string id = "";
string strStr="";
for (int i = 1; i <= 8; i++)
{
id = "MainProducts" + i;
TextBox tbbb= this.FindControl(id) as TextB……
[/Quote]
+1
风一样的大叔 2012-04-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

C# code

string id = "";
string strStr="";
for (int i = 1; i <= 8; i++)
{
id = "MainProducts" + i;
TextBox tbbb= this.FindControl(id) as TextB……
[/Quote]这个可以用
small_horse86 2012-04-19
  • 打赏
  • 举报
回复
2楼正解
苹果哥 2012-04-19
  • 打赏
  • 举报
回复
MainProducts1.text+MainProducts2.text+...

直接+不行吗?
  • 打赏
  • 举报
回复

string id = "";
string strStr="";
for (int i = 1; i <= 8; i++)
{
id = "MainProducts" + i;
TextBox tbbb= this.FindControl(id) as TextBox;

strStr += tbbb.Text;
}
zllllz6 2012-04-19
  • 打赏
  • 举报
回复
遍历 页面上的 textbox呗

62,267

社区成员

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

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

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

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