110,534
社区成员
发帖
与我相关
我的任务
分享
TextBox tx = (TextBox)sender;
if (tx.Text.Trim().Length > 0)
{
}
else
{
}
private void simpleButton3_Click(object sender, EventArgs e)
{
if (groupBox1.Controls.Cast<Control>().Where(T => T is TextBox)
.All(T => (T as TextBox).Text.Trim().Length == 0))
{
MessageBox.Show("有空的单元格");
}
else
{
MessageBox.Show("没有空的单元格");
}
}
//比如,把所有要检测的TEXT控件放到名为palInformation的 palel控件中,。。。
if( palInformation.Controls.OfType<TextBox >().All(a => a.Text.Length> 0))
{
//Pass and do something
}
else
{
MessageBox.Show("No pass");
return;
}
不知道这样可不可以,你试。。。
if (groupBox1.Controls.Cast<Control>().Where(T => T is TextBox).Any(T => (T as TextBox).Text.Length == 0))
{
MessageBox.Show("有空的单元格");
}
else
{
MessageBox.Show("没有空的单元格");
}
纠正下 All<TSource>确定序列中的所有元素是否满足条件。Any<TSource 确定序列是否包含任何元素。
$(":text").each(function () { //遍历所有的 type="text" 的 <input> 元素
if ($(this).val()=="") { //判断是否为空
alert("未填写完整,请核对后再提交");
$(this).focus();
return;
}
});
var textbox=sender as textbox
跟
var textbox=(textbox)sender;
不一样..个强制转换而已..根本就不是这个问题...
因为他这里面的Controls的数量只有1.....如果我没猜错 id应该等于form1...
所以 他这个问题 应该用..
for int i=1 i<=40 i++
{
var textbox=page.findcontrol("textbox"+i.tostring()) as textbox;
if .......
//do something
}
话不多说,,.try it ,.,
foreach(var ctl in this.Control)
{
if((ctl as TextBox).Text.Trim().Length < 0x1){
MessageBox.Show("没有数据");
}
else{
///
///
//
}
}