This is a migrated thread and some comments may be shown as answers.

Possibly rebinding multiple RadGrid using for loop?

2 Answers 46 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 18 Jul 2014, 12:41 PM
Dear All,

I have a project that contains numerous radgrid, and need to rebind them all in timely manner. I'm just wonder will it be even possible to use a for loop to reduce the length of my code?

Some thing like this (just an idea, obviously the type conversion is incorrect):

//For RadGrid1, RadGrid2,... to RadGrid20, I have a click function using a button
 protected void Refresh_Click(object sender, EventArgs e)
        {
                string raw_radgridname = "RadGrid";
                string radgridname = "";

                for (int i = 0; i<20; i++)
                {     
                        radgridname = "";
                        radgridname = raw_radgridname + Convert.ToString(i);
                       (radgridname as RadGrid).Rebind();
                } 
        }

Many Thanks!

2 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 18 Jul 2014, 12:57 PM
Correction: for (int i = 1; i<21; i++)
0
Tim
Top achievements
Rank 1
answered on 20 Jul 2014, 07:48 PM
Problem solved. Done by:

string radname = "RadGrid";
 ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("MainContent");
            for (int i = 1; i <= 10; i++)
            {
                radname= radname+ Convert.ToString(i);
                RadGrid radgrid = cph.FindControl(radname) as RadGrid;
                radgrid .DataSource = GetDataTable();
                radgrid .Rebind();
}
Tags
Grid
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Share this question
or