循环遍历页面内的所有TextBox控件,将TextBox文本框的内容作为查询条件,跳过空值的TextBox。后台代码该怎么写。
不要单个的判断,万一页面内有100个TextBox控件,单个写的话岂不是太麻烦了,最好运用类似 foreach (Control c in this.Controls)这种循环方法。
附上页面设计图,哪位大虾能帮忙写个示例出来。注意编程语言是C#

------解决思路----------------------
foreach (Control c in this.Controls)
-》
这不是你都知道 怎么写么?if判断不就行了。
string filter ="";
if((c is TextBox) && (c is TextBox).Text!=""){
TextBox txt = c as TextBox;
filter += txt.Text;
}
可能有错,手动打的。
------解决思路----------------------
string strWhere = string.Empty;
foreach (Control cur in Controls)
{
if (cur is TextBox )
{
TextBox tb = (TextBox)cur;
if(!string.IsNullOrEmpty(tb.Text.Trim())){
strWhere += tb.ID + "='" + tb.Text + "' and ";
}
}
}
strWhere += " 1 = 1";
你试试看,我没测过 ...