这样遍历界面上的textbox值 foreach (Control cor in this.Page.Controls) { if (cor.GetType().Equals(TextBox)) { string str = ""; str += (cor as TextBox).Text; } }
StringBuilder sb=new StringBuilder(); foreach (Control ctr in this.Controls) { if (ctr.GetType().ToString()=="System.Windows.Forms.TextBox") { if (ctr.Text.Trim().Length != 0) { sb.Append(ctr.Text); } } } if (sb.ToString().Trim().Length != 0) { MessageBox.Show(sb.ToString()); }
string value = ""; foreach (Control c in Controls) { if (c is TextBox) { value += ((TextBox)c).Text; } }
string s = ""; foreach (Control c in this.Controls) { if (c.GetType().Name.Equals("TextBox")) { s += c.Text; } }
这种计算我就用在客户端上做了 var txt = document.getElementsByTagName("input"); var aa = ""; for(var i=0;i<txt.length;i++) { if(txt[i].type=='text') { aa = txt[i].value+aa; } }然后把aa赋值给一个隐藏控件 服务器上直接取
string result=""; string FindTextBox(Control ctl) { foreach (Control parent in ctl.Controls) { foreach (Control c in parent.Controls) { if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox") result = ((TextBox)c).Text; FindTextBox(parent); } } return result; } 手写的,没有测试过,你自己试试
foreach (Control cor in this.Page.Controls)
{
if (cor.GetType().Equals(TextBox))
{
string str = "";
str += (cor as TextBox).Text;
}
}
foreach (Control ctr in this.Controls)
{
if (ctr.GetType().ToString()=="System.Windows.Forms.TextBox")
{
if (ctr.Text.Trim().Length != 0)
{
sb.Append(ctr.Text);
}
}
}
if (sb.ToString().Trim().Length != 0)
{
MessageBox.Show(sb.ToString());
}
string value = "";
foreach (Control c in Controls)
{
if (c is TextBox)
{
value += ((TextBox)c).Text;
}
}
string s = "";
foreach (Control c in this.Controls)
{
if (c.GetType().Name.Equals("TextBox"))
{
s += c.Text;
}
}
var aa = "";
for(var i=0;i<txt.length;i++)
{
if(txt[i].type=='text')
{
aa = txt[i].value+aa;
}
}然后把aa赋值给一个隐藏控件 服务器上直接取
string result="";
string FindTextBox(Control ctl)
{
foreach (Control parent in ctl.Controls)
{
foreach (Control c in parent.Controls)
{
if (c.GetType().ToString() == "System.Web.UI.WebControls.TextBox")
result = ((TextBox)c).Text;
FindTextBox(parent);
}
}
return result;
}
手写的,没有测试过,你自己试试