winfrom 判断为空 c# winfrom 判断为空 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 foreach遍历控件集合,里面if判断即可 foreach(Control c in this.Controls){ if(c is TextBox) { if(string.IsNullorEmpty((c as TextBox).Text)) { //是否为空 } }} 控件不能为空设置示例<asp:TextBox ID="txtName" runat="server" Width="235px" Font-Size="9pt"></asp:TextBox>//用户名设置<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" Font-Size="9pt" ErrorMessage="用户名不允许为空">*</asp:RequiredFieldValidator>//不能为空设置<asp:Button ID="btnCheck" CssClass="ButtonCss" runat="server" CausesValidation="False" Text="检测用户" Font-Size="9pt" OnClick="btnCheck_Click" Width="120px" />//检测设置//检测事件是否可以操作 protected void btnCheck_Click(object sender, EventArgs e) { SqlData da = new SqlData(); SqlDataReader read = da.ExceRead("select * from tb_Blog where UserName='" + this.txtName.Text + "'"); read.Read(); if (read.HasRows) { if (this.txtName.Text == read["UserName"].ToString()) { Response.Write("<script language=javascript>alert('对不起,该用户已经存在!');location='Register.aspx'</script>"); } }//CodeGo.net/ else { Response.Write("<script language=javascript>alert('恭喜您,该用户可以登陆!');location='javascript:history.go(-1)'</script>"); } read.Close(); } foreach遍历控件集合,里面if判断即可 这个可以 如果是指定的几个控件 那个多写几条if bool is有空数据;//foreach(Control c in this.Controls){ if(c is TextBox) { if(string.IsNullorEmpty((c as TextBox).Text)) { is有空数据 = true; return; } }} is有空数据 = false;// 所有文本控件不为空 bool is有空数据;//foreach(Control c in this.Controls){ if(c is TextBox) { if(string.IsNullorEmpty((c as TextBox).Text)) { is有空数据 = true; return; } }} is有空数据 = false;// 所有文本控件不为空 你是要判断,还是要控制?判断: 方法1:循环容器中(你的文本控件是放在哪个容器中的,比如panl,form)的控件,如果是文本,则判断是否为空,如果所有的文本不是放在同一个容器中的,那么写个递归方法 方法2:将所有文本控件的值改变事件指向同一个方法,根据当前焦点来获得是哪个文本控件控制:同上,原理一样,用正则控制不能为空, 排序问题 C#与工业控制 加密狗出错。 请教一个C#操作XML的问题,请大家帮忙研究下 请问在C# 下如何使用内存映射文件以及怎么使用? 关于Socket的问题,急!!! 求一份C#自动提醒功能 请问怎么躲避弹出窗口拦截?? 请教高手!如何将a和b做hash后得到MD5 Hash字符串 GRIDVIEW刷新后定位当前行的问题 C#可以像matlab那样对数据处理出图么 水电表录入的实现
{
if(c is TextBox)
{
if(string.IsNullorEmpty((c as TextBox).Text))
{
//是否为空
}
}
}
<asp:TextBox ID="txtName" runat="server" Width="235px" Font-Size="9pt"></asp:TextBox>//用户名设置
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName" Font-Size="9pt" ErrorMessage="用户名不允许为空">*</asp:RequiredFieldValidator>//不能为空设置
<asp:Button ID="btnCheck" CssClass="ButtonCss" runat="server" CausesValidation="False" Text="检测用户" Font-Size="9pt" OnClick="btnCheck_Click" Width="120px" />//检测设置
//检测事件是否可以操作
protected void btnCheck_Click(object sender, EventArgs e)
{
SqlData da = new SqlData();
SqlDataReader read = da.ExceRead("select * from tb_Blog where UserName='" + this.txtName.Text + "'");
read.Read();
if (read.HasRows)
{
if (this.txtName.Text == read["UserName"].ToString())
{ Response.Write("<script language=javascript>alert('对不起,该用户已经存在!');location='Register.aspx'</script>");
}
}//CodeGo.net/
else
{
Response.Write("<script language=javascript>alert('恭喜您,该用户可以登陆!');location='javascript:history.go(-1)'</script>");
}
read.Close();
}
foreach(Control c in this.Controls)
{
if(c is TextBox)
{
if(string.IsNullorEmpty((c as TextBox).Text))
{
is有空数据 = true;
return;
}
}
}
is有空数据 = false;// 所有文本控件不为空
foreach(Control c in this.Controls)
{
if(c is TextBox)
{
if(string.IsNullorEmpty((c as TextBox).Text))
{
is有空数据 = true;
return;
}
}
}
is有空数据 = false;// 所有文本控件不为空
判断:
方法1:循环容器中(你的文本控件是放在哪个容器中的,比如panl,form)的控件,如果是文本,则判断是否为空,如果所有的文本不是放在同一个容器中的,那么写个递归方法
方法2:将所有文本控件的值改变事件指向同一个方法,根据当前焦点来获得是哪个文本控件控制:同上,原理一样,用正则控制不能为空,