简体   繁体   English

使用循环来设置Webform中所有RadGrid的属性?

[英]Use loop to set property of all RadGrids in webform?

I have several radgrids in my webform and I want to set all the visible property to false without having to specify the control name. 我的网络表单中有多个radgrids,我想将所有visible属性设置为false,而不必指定控件名称。

How can I do this with a loop? 我该如何循环?

Thanks. 谢谢。

Use the jquery. 使用jQuery。

$("radgrids").prop("visible",false);

This will set all the radgrid element's visible property to false. 这会将所有radgrid元素的visible属性设置为false。
Hope this works. 希望这行得通。 Don't forget to add the jQuery library. 不要忘记添加jQuery库。

There is no automated way to do such a task in .NET .NET中没有自动化的方法来执行此类任务

I think you will need a method like FindControlRecursive() that will recursively go through all controls on the page, and it will compare each control type with RadGrid, eg: 我认为您将需要像FindControlRecursive()这样的方法,该方法将递归地遍历页面上的所有控件,并将每种控件类型与RadGrid进行比较,例如:

protected void Page_Load(object sender, EventArgs e)
{
    for (int i = 0; i < form1.Controls.Count; i++)
    {
        if ((form1.Controls[i]) is RadGrid)
            Response.Write(string.Format("found a grid with ID: {0}<br />", form1.Controls[i].ClientID));
    }
}

where this would need to be recursive, of course to get all controls on the page. 当然,这需要递归,以便在页面上获得所有控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM