如何循环显示按钮使其可见? [英] How do I loop through buttons making them visible?

查看:56
本文介绍了如何循环显示按钮使其可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种简单的方法来遍历我的asp.net页面上的按钮来切换它们的可见性。我目前在页面上有30个按钮。我从我的数据库中获取数据,我想根据计数显示按钮的数量。请帮助

Hi, I would like to know if there is a simple way to loop through buttons on my asp.net page to toggle their visibility. I currently have 30 buttons on my page. I get count from my database, I want to make the number of buttons visible based on the count. Please help

推荐答案

此代码将遍历所有按钮并使其可见。

This code will iterate through all the buttons and make them visible.
foreach(Control ctrl in this.Controls)
{
    if(ctrl is Button)
        ((Button)ctrl).Visible = true;
}



未在IDE上测试,但应该可以使用。 ;)



-KR


Not tested on IDE, but should work. ;)

-KR


int visibleCount = 0;

int InvisibleCount = 0;



foreach(控制ctrl in this.Controls)

{

if(ctrl is Button)

{

if((Button)ctrl).visible == true)

{

InvisibleCount = InvisibleCount + 1;

((按钮)ctrl).Visible = false;

}

其他

{

visibleCount = visibleCount + 1;

((按钮)ctrl).Visible = true;

}

}

}





上面的循环将遍历所有按钮并检查它们的可见性并分别计算它们。



我还没有在IDE上测试它。因此,如果编译时出现问题,请修复它。
int visibleCount=0;
int InvisibleCount=0;

foreach(Control ctrl in this.Controls)
{
if(ctrl is Button)
{
if ((Button)ctrl).visible==true)
{
InvisibleCount=InvisibleCount+1;
((Button)ctrl).Visible = false;
}
else
{
visibleCount=visibleCount+1;
((Button)ctrl).Visible = true;
}
}
}


Above loop will iterate through all buttons and check their visibility and count them respectively.

I have not tested it on IDE. So if compile time issues will come, please fix it.


这篇关于如何循环显示按钮使其可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆