private void button1_Click(object sender, System.EventArgs e)
{
int i=0;
MyCollection textboxCollection = new MyCollection();//定以的集合,以便foreach调用!!!!!!
textboxCollection.Add(textbox1);
textboxCollection.Add(textbox2);
textboxCollection.Add(textbox3);
textboxCollection.Add(textbox4);
textboxCollection.Add(textbox5);
textboxCollection.Add(textbox6);
MyCollection labelCollection = new MyCollection();
labelCollection.Add(label1);
labelCollection.Add(label2);
labelCollection.Add(label3);
labelCollection.Add(label4);
labelCollection.Add(label5);
labelCollection.Add(label6);
foreach(TextBox newtextbox in textboxCollection)
{
foreach(Label newlabel in labelCollection)
{
i++;
newtextbox.Name="textbox"+i.ToString();
if(newtextbox.Text=="")
{
newlabel.Name="label"+i.ToString();
MessageBox.Show(newlabel.Text+"不能为空!!");
newtextbox.Focus();
return;
}
}
}
}
//代码错在那里,我一点也看不出来!!!!!!
{
int i=0;
MyCollection textboxCollection = new MyCollection();//定以的集合,以便foreach调用!!!!!!
textboxCollection.Add(textbox1);
textboxCollection.Add(textbox2);
textboxCollection.Add(textbox3);
textboxCollection.Add(textbox4);
textboxCollection.Add(textbox5);
textboxCollection.Add(textbox6);
MyCollection labelCollection = new MyCollection();
labelCollection.Add(label1);
labelCollection.Add(label2);
labelCollection.Add(label3);
labelCollection.Add(label4);
labelCollection.Add(label5);
labelCollection.Add(label6);
foreach(TextBox newtextbox in textboxCollection)
{
foreach(Label newlabel in labelCollection)
{
i++;
newtextbox.Name="textbox"+i.ToString();
if(newtextbox.Text=="")
{
newlabel.Name="label"+i.ToString();
MessageBox.Show(newlabel.Text+"不能为空!!");
newtextbox.Focus();
return;
}
}
}
}
//代码错在那里,我一点也看不出来!!!!!!
解决方案 »
- C#集成环境里有没有直接由断点函数追溯到被调用者的功能?
- 面试答疑: 面向对象 与 面向过程 他们的开发方式都是怎么样的啊
- 求一条sql查询语句
- 如何判断一个exe文件,执行后安装完毕?
- dataGridView绑定数据后
- 学生的感慨:.NET确实强大,但正因为它的强大,我感觉程序员以后真的会变成装配工了.
- 用VS2005和SQL2000做的B/S模式的软件怎么打包成EXE文件
- C# webservice 求助
- 求助,如何用Socket下载指定地址的文件啊?
- 怎样从文本文件中一个一个的读入字符?
- 关于用c#.net 2003 制作一个 asp.net 网站的流程,请大家指点一下;
- datagrid 编辑时聚焦某一行记录问题
{
int i=0;
MyCollection textboxCollection = new MyCollection();//定以的集合,以便foreach调用!!!!!!
textboxCollection.Add(textbox1);
textboxCollection.Add(textbox2);
textboxCollection.Add(textbox3);
textboxCollection.Add(textbox4);
textboxCollection.Add(textbox5);
textboxCollection.Add(textbox6);
MyCollection labelCollection = new MyCollection();
labelCollection.Add(label1);
labelCollection.Add(label2);
labelCollection.Add(label3);
labelCollection.Add(label4);
labelCollection.Add(label5);
labelCollection.Add(label6);string textBoxIsEmpty ;
foreach(TextBox newtextbox in textboxCollection)
{
if(newtextbox.Text ==String.Empty)
{
textBoxIsEmpty = textBoxIsEmpty + newtextbox.Name +"\n" ;}
}
MessageBox.Show(textBoxIsEmpty + +"不能为空!!");
return ;
}
这个要这样写
newtextbox.Name=((TextBox)(Page.FindControl("textbox"+i.ToString())).Text
注,用Page.不一定能找到,用递归或textbox所在最内一层容器
xiaoqhuang 也谢谢你了,你说的是好象是asp.net,我是在Window编程中出现的问题
foreach(TextBox newtextbox in textboxCollection)
{
j++
if(newtextbox.Text=="")
{
foreach(Label newlabel in labelCollection)
{
i++;
if(i==j)
{
MessageBox.Show("label"+1.ToString()+"不能为空!!");
newtextbox.Focus();
return;
}
}
}
}
}
newlabel.Name="label"+i.ToString();
======
上面这两句莫名其妙, 分别对TextBox和Label控件的Name属性重新赋值了!!!??其议何为?是否这样:foreach(TextBox newtextbox in textboxCollection)
{
i++;
if(newtextbox.Text=="")
{
MessageBox.Show(labelCollection[i].Text+"不能为空!!");
newtextbox.Focus();
return;
}
}对语法不太熟悉, 也没验证, 上面代码仅一思路, 错误之处请各位大侠指正
同时也感谢大家对我的帮助!!!!!!!!!!!!!!!!
foreach(TextBox newtextbox in textboxCollection)
{
if(newtextbox.Text=="")
{
MessageBox.Show(labelCollection[i].Text+"不能为空!!");
newtextbox.Focus();
return;
}
i++;//这个写在这就没事了,否则就会从1开始!!!!!!!!!
}