Use loop to set property of all RadGrids in webform?

Total Post:110

Points:776
C# 
C#
 885  View(s)
Ratings:
Rate this:

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. 

How can I do this with a loop? 

Thanks.

  1. Post:378

    Points:2694
    Re: Use loop to set property of all RadGrids in webform?

    Hi Jeet, 


    try this:

    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));
        }
    }

      Modified On Apr-05-2018 06:14:35 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!