各位,请教一个关于public bool IsSame()如何写。散分!!!

eagle_hb 2003-09-11 10:49:19
有这么多控件,通过IsSame()判断他们的.Text都不能相同。。命名不能改了,要求简单明了!
protected System.Web.UI.WebControls.TextBox Text1;
protected System.Web.UI.WebControls.TextBox Text2;
protected System.Web.UI.WebControls.TextBox Text3;
protected System.Web.UI.WebControls.TextBox Text4;
protected System.Web.UI.WebControls.TextBox Text5;
protected System.Web.UI.WebControls.TextBox Text6;
protected System.Web.UI.WebControls.TextBox Text7;
protected System.Web.UI.WebControls.TextBox Text8;
protected System.Web.UI.WebControls.TextBox Text9;
protected System.Web.UI.WebControls.TextBox Text10;


protected System.Web.UI.WebControls.TextBox Count1;
protected System.Web.UI.WebControls.TextBox Count2;
protected System.Web.UI.WebControls.TextBox Count3;
protected System.Web.UI.WebControls.TextBox Count4;
protected System.Web.UI.WebControls.TextBox Count5;
protected System.Web.UI.WebControls.TextBox Count6;


protected System.Web.UI.WebControls.TextBox TextArea1;
protected System.Web.UI.WebControls.TextBox TextArea2;
protected System.Web.UI.WebControls.TextBox TextArea3;
protected System.Web.UI.WebControls.TextBox TextArea4;
protected System.Web.UI.WebControls.TextBox TextArea5;
protected System.Web.UI.WebControls.TextBox TextArea6;
...全文
58 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
eagle_hb 2003-09-12
  • 打赏
  • 举报
回复
来吧,大家来UP,我马上散分!!
eagle_hb 2003-09-12
  • 打赏
  • 举报
回复
bool IsSame(object sender)
{
bool same=true;
string[] xx=new string[22];
int x=0;
Control form;
form=((Control)sender).Parent;
foreach(Control control in form.Controls)
{
if(control.GetType()==typeof(TextBox))
{
xx[x]=((TextBox)control).Text;
x++;
}
}
for(int i=0;i<xx.Length-1;i++)
{
for(int j=i+1;j<xx.Length;j++)
{
if(xx[i]!=""&&xx[j]!="")
{
if(xx[i]==xx[j])
same=false;
}
}
}
return same;
}

谢谢大家的提醒,在大家的提醒下,我终于把这个方法写出来了。
zhangjie1234 2003-09-11
  • 打赏
  • 举报
回复
foreach(Control c in Controls)
{
if(c == typeof(textBox))
{.............}
}
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
怎么没有人回签呢??
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
那样会把人搞死的。如何得到TEXTBOX集合,
littlechang 2003-09-11
  • 打赏
  • 举报
回复
最简单的方法,一个个的比较。
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
UP
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
贴出代码?!好不好!
diaopeng 2003-09-11
  • 打赏
  • 举报
回复
不难,用controls可以判断如果是TextBox,那么造型并判断其TEXT是不是相同
foreach()
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
再UP一下!!!
ArLi2003 2003-09-11
  • 打赏
  • 举报
回复
foreach(Control c in Controls) {
if(c.GetType() == typeof(System.Windows.Forms.TextBox)) {
MessageBox.Show(c.Text);
}
}

//推荐用控件数组
fly_miss 2003-09-11
  • 打赏
  • 举报
回复
dim c as control
for each c in me.controls
if typeof (c) is textbox then
.........
response.write(c.name)
end if
next
huarick 2003-09-11
  • 打赏
  • 举报
回复
UP
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
最后一UP!
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
帮帮我吧
eagle_hb 2003-09-11
  • 打赏
  • 举报
回复
不能通过呀!!!c == typeof(textBox)出错!!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧