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

Bypassing paging to get all Grid IDs

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 13 Jan 2009, 09:37 AM
Hello,

I have a Grid with paging enabled. I am creating an export button inside the footer to exports Data from grid based on the current Grid data. Let's say someone filtered the Grid and we now have like 30 rows that spans over 4 pages. The grid has an ID as a DataKeyName.

What I want is to get all the IDs, not only of the first page but from all the grid and pass them to a Stored Procedure to get me shaped data I want for my export, bind it to a special Grid and export the data to Excel.

How can I be able to get all the IDs from the Grid and not just the ones from the current page.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Joseph
Top achievements
Rank 1
answered on 13 Jan 2009, 11:29 AM
Here is the complete scenario :

The grid is connected to a table in the DB.

In the footer I have created a custom button that will exports data using grid export capabilities.

Let's say first time the grid is loaded. Then a user filteres the grid and hit Export.

What I want to do is to get the IDs of the filtered data ( Paging is enabled by default ), run a Stored Procedure, get a DataTable, binded to a different grid ( custom schema ) and export to excel from this grid.

Now after the export I want the Main grid to maintain its paging.

Is it possible?

Thanks
0
Shinu
Top achievements
Rank 2
answered on 14 Jan 2009, 06:03 AM
Hi Joseph,

One suggestion will be to store the CurrentPageIndex of the main Grid in a ViewState and set Paging to false in the click event of the Export button. Once the second Grid is exported set the Paging back to true for the Main Grid and set its CurrentPageIndex from the ViewState.

CS:
protected void Button1_Click(object sender, EventArgs e) 
    { 
        //store the currentpageindex of the Main Grid 
        ViewState["CurrentIndex"] = RadGrid1.MasterTableView.CurrentPageIndex; 
 
        //set paging of Main Grid to false 
        RadGrid1.MasterTableView.AllowPaging = false
        RadGrid1.MasterTableView.Rebind(); 
 
        //to access and store the ID value for the entire rows in Main Grid 
        ArrayList keyvalueArr = new ArrayList(); 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            keyvalueArr.Add(Convert.ToInt16(item.GetDataKeyValue("ProductID"))); 
           
        } 
        
        // Bind the Second Grid here 
        //... 
        // export the second Grid 
        RadGrid2.ExportSettings.OpenInNewWindow = true
        RadGrid2.MasterTableView.ExportToExcel(); 
 
        //set Paging back to true for the Main Grid 
        RadGrid1.MasterTableView.AllowPaging = true
        RadGrid1.MasterTableView.CurrentPageIndex = Convert.ToInt16(ViewState["CurrentIndex"]); 
        RadGrid1.MasterTableView.Rebind(); 
    } 


Thanks
Shinu.
Tags
Grid
Asked by
Joseph
Top achievements
Rank 1
Answers by
Joseph
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or