【发布时间】:2016-06-28 02:49:45
【问题描述】:
private void btnSaveInformation_Click(object sender, EventArgs e)
{
foreach (Control child in Controls)
{
if (child is TextBox)
{
TextBox tb = child as TextBox;
if (string.IsNullOrEmpty(tb.Text))
{
tb.Text = @"N/A";
}
}
}
//var bal = new StudentBal
//{
// FirstName = txtFirstName.Text
//};
//bal.InsertStudent(bal);
}
我想要实现的是让系统检查是否有任何空白复选框,并且我在表单中有很多,如果是空白,则分配一个值“N/A”。我的代码做错了什么?谢谢。
【问题讨论】:
-
你试过
TextBox tb = (TextBox)child; -
没有错。您的文本框是否位于其他控件(如组框或面板)中?
-
哦。它位于组框内。应该怎么做?