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

RadGrid CurrentPageIndex Questions [Jerry]

2 Answers 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rama
Top achievements
Rank 1
Rama asked on 26 Aug 2008, 02:01 PM
Telerik Support,

I posted this yesterday but did not have any account information.  I'll try again today.

Basically, I have some Asp.net Server Side logic for IsDirty checking.  To check and see if the web page is dirty (data has changed).  I have added some code to my master page to work with all pages. I have implemented this code in one page and everything is working fine.  However, with the RadGrid control I'm seeing some issues with the CurrentPageIndex when manually setting this page in c# code. 

Code:

case "RADGRIDVIEW":

    {

            RadGridView rgv = (RadGridView)childControl;

            int saveCurrentPageIndex = rgv.CurrentPageIndex;

            EventArgs e = new EventArgs();

            for (int p = 0; p < rgv.PageCount; p++)

            {

                    rgv.CurrentPageIndex = p;

                    rgv.Rebind();

                    for (int r = 0; r < rgv.Items.Count; r++)

                    {

                            for (int c = 0; c < rgv.Items[r].Cells.Count; c++)

                            {

                                    controlValues.Append(rgv.ClientID);

                                    controlValues.Append(

"_Pg" + p + "Row" + r + "Col" + c);

                                    controlValues.Append(

":");

                                    controlValues.Append(rgv.Items[r].Cells[c].Text);

                                    controlValues.Append(

",");

                            }

                    }

            }

            rgv.CurrentPageIndex = saveCurrentPageIndex;

//Reset page to saved page index.

            rgv.Rebind();

            break;

}



Ok, so now I call this code in a method to build the initial string of control ID and data.  I this case I'm cycling through the RadGrid (we inherit from RadGrid to create RadGridView) cells to build the string in a string builder.  First time through this code the grid is empty.  Second time the grid has 11 records in two page.  The second time the grid is cycled through this code works fine and all 11 records are added to the string builder.  The a submit button is clicked and the same code is called to create a comparison string builder object.  However, this time the code (in debug mode) works a little different.  This time the page is set to index 0 (page 1) and it has 10 record in the page. Everything is ok.  Then when page index (rgv.CurrentPageIndex) is set to 1 for page 2.  When the debug step is looking at the rgv.Items.Count it still says 10 records (rows).  The code again adds the ten records to the string builder.  It's like the page did not really change.  Ok, now last night I tried to do the same thing but this time I moved the page to page 2. Then did the same code 1, 2 and 3 times.  This time the code worked the same way on pass 1 and 2.  But on 3rd pass the page 1 (index 0) had one record (row) and on the 2nd page it to had the same one record.

Please let me know if here is an issue with this control (RadGrid) or if I'm doing something wrong!  Thanks!

JerryM (using Pradeeps account!)

2 Answers, 1 is accepted

Sort by
0
Rama
Top achievements
Rank 1
answered on 26 Aug 2008, 04:31 PM
One more piece of information:

I decided to try changing the page size in code instead of walking through the pages.  So saved the rgv.PageSize value in an integer variable. Then set the rgv.PageSize property to rgv.Items.Count + 1 and call rgv.Rebind(). After my two nested loops I reset the PageSize to 10 (the saved value).  For the initial pass the RadGrid data is empty.  Pass 2 the data has 11 rows.  Pass 2 works fine.  However, on pass 3 the PageSize is changed to 11 but the data in rgv.Items.Count is still 10 rows.

There seems to be an issue manually trying to cycle through the rgv.Items[r].Cells[c].Text collection.  Note: r is the row and c is the column.

If Telerik Support has a better way to cycle through the data in the Items collection please let me know.  I don't want to use some event to get to the grid data.  I need to be able to dynamically extract the data and control properies at will.

Thanks in advance! Any help is greatly appreciated!!!

JerryM
0
Rosen
Telerik team
answered on 29 Aug 2008, 01:14 PM
Hi Rama,

As I'm not exactly sure what the behavior you are trying to achieve is, I have attached a simple page which demonstrates a possible implementation of how to page grid programmatically and retrieve its items' values. Please give it a try and see if this helps.

Best regards,
Rosen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Rama
Top achievements
Rank 1
Answers by
Rama
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or