Gridview paging enabled. Has checkbox to select the row . If user select the checkbox on one page and move to 2nd page to select the rows there also to export the selected rows to excel. But doing so


I am using Gridview and that has paging enabled. Using checkbox to select the particular row of the gridview to export the selected rows to the excel . Everything is working fine except for one case.

Let user selected the "check" box for, five rows which user would like to export to excel (two of rows on page 1 of results and 3 of them on page 2 of results), however it only exports the 3 row details from page 2, because it seems to de-select the 2 rows from page 1 when I move to page 2 and vice versa. The code i am using is as :

protected void BtnExcel_Click(object sender, EventArgs e)
        string excel = string.Empty;
        foreach (GridViewRow row in GridView1.Rows)
            CheckBox cb = (CheckBox)row.FindControl("rowlevelcheck");
            if (cb.Checked)
                excel += "'" + Convert.ToString(GridView1.DataKeys[row.RowIndex].Value) + "',";               
        if (excel.Length > 0)
            excel = excel.Substring(0, excel.Length - 1);
            Session["excelresult"] = excel;


On SearchResultReport page i am just exporting the results to excel by using 

Response.ContentType = "application/vnd.xls"; 


Please let me know how i can handle this case. This is urgent . 


9/26/2007 5:50:28 PM 72751 articles. 3 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 17

From  what I understand, paging won't keep your selections of the check boxes on the previous page. As far as the page is concerned, when you paged to the next one, it's a "refresh" if you will.

On the top of my head, what you can do is to have a hidden field and remember what you selected previously via an "id" of some sort(using javascript) Every time, as each row is rendered, check with the hidden variable, if your id is in there, check it, if not, don't check it.

Of course, in your case, that's only the first part of the operation. When your excel is rendered, you should then get the values from the hidden variables and render it that way.

That's  how I would implement it.

Liming Xu
Jumptree ASP.NET 2.0 Project Management - With Source Code, Free to Non Profit Org and Effectively Manage Projects/Tasks/Milestones
9/26/2007 7:13:41 PM

Similar Artilces:

Selecting a gridview row and keeping the last selected row in a gridview highlighted after mouse moves over a new row.
What is the best way to show a gridview row highlighted once selected and keep it highlighted once the mouse moves over a different row? Thanks, Steve hi,you can use <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="#FFFFFF" /> plz let me know if i misunderstood you Thanks for your help. One problem; however, is that after the row has been selected and I check the "grid.SelectedIndex" it has a value of -1 and not the index of the row that was selected on the grid. What do you recommend? Thanks, Steve hi, sorry i din...

Select checkbox or select row
I need a grid where I can select a checkbox or select everything else in the row. So I could select the checkbox and hit the delete button and the row is deleted in the database. Or I could click on one of the other columns in the row and the item is opened in another page. (Kinda the way Yahoo Mail works) Does anyone know if that is possible ? (And have you seen an example if it is ?) You mean thisprotected void Button1_Click(object sender, EventArgs e){    for (int i = 0; i < GridView1.Rows.Count; i++)        {   &nbs...

How to make a gridview row clickable for select, and keep the selection through sorting & paging?
I have a Gridview loaded with data using sqldatasource, and a Formview loaded with details for a selected row of the Gridview. The Gridview supports sorting and paging. I would like to accomplish the followings: 1. The Gridview row will be clickable (without the select button) with the row highlighted and the FormView displaying the corresponding data. 2. When the Gridview is first loaded, I want the first row of the GridView to be selected (highlighted) and the FormView displaying the data for this first row.  3. When the Gridview is sorted or paged, the select...

Select All CheckBoxes in all colums of the Row when the first column checkbox is selected..
Hello Guys, I am stuck in a problem. I have a Datagrid. and I am having checkboxes in all the columns and all the rows. My Problem is when I select a Checkbox in First column of any row, all the checkboxes in that particular row should also be selected. How can I do this.... Please help. Thanks in advance.Mark it as Answer if you find it Helpful.Shailen  function checkAllInRow( cb ){    var row = cb.parentNode.parentNode; //shoud give us the row    var cbs = row.getElementsByTagName("input"); //will give us all of the inputs in the row&nb...

How do I total selected rows on Checkbox selection
I have a GridView with a checkbox template field.  One of the fields is Population and I need to increment through the GridView every time a checkbox is selected and calculate a total Population for all selected checkboxes.  Questions are: 1) I am coding in C#, what kind of code behind do I need to calculate the sum of the population field for selected rows in the GridView?2) What kind of event or postback do I need to enable to cause re-caculation everytime a checkbox is selected by the user? Existing Code below: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumn...

Iwant to select a row and column in gridview with select radiobutton. but No checked change event.below put a button .if click that button to seleced row values will select
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row.
 Hi, Let say I've 4 rows in a table. I want to select top 3 rows except the first from 4 rows of a Table. It should select from top 2 row,top3 row and top4 row. Thanks in advance Asghar Ali Mohammed Designer and Developer)Do not forget to "MARK AS ANSWER" on the post that helped you. If you can use Linq, you can use Skip., EdMicrosoft MVP - ASP/ASP.NET Hii dear..U can fire the Query select Top(3) from Table1 order by id desc.. "A conclusion is whe...

Selecting the multiple rows in GridView and inserting the selected rows to another Gridview & Performing some operations on it
 Dear All, I have become mad for solving this problem. Please Help me. I have a Gridview bound to a datasource. I inserted the CheckBox Control in Templet to select certain rows. Gridview1 contains some products id & name.I want to insert the selected rows in to second Gridview  and in the second Gridview I need to add two more colums AdvicedQty & AcceptedQty(TextBox Cotrol).The user will select few products in Gridview1 & clicks add which will be added another gridview then in second Gridview he enters the AdviceQty & AcceptedQty.After entering the data he cli...

Paging page change stops select row from working
I have a gridview in an UpdatePanel. When I select a row from my results some of the data from that row is entered into my form. When I change page in the gridview and try to select a row it throws an error in an alert box: Through digging I had discovered that this is probably related to AJAX somehow. I am not certain of this, and I have no Response.Wrtie() or anything that would obviously cause this. It only happens when I change page and then select a row. Here is my Page Changing code:   conn.Open(); OracleCommand comm = conn.CreateCommand(); comm.CommandText = Pa...

How to select all rows from all pages in a Gridview??
i got this  ....Dim dr As GridViewRow For Each dr In Me.GridView1.RowsDim check As CheckBox = CType(dr.FindControl("CheckBox1"), CheckBox) check.Checked = True Next But it works but just in the selected current page ..... Any help is wellcome ... Thanks in advance  You Need to maintain state of all checkbox's selection in some session with some unique value like ID, and need to check it in the list each time checking operation has done on checkbox. and u need to maintain the state in page index changed also.Regards,Mulukutla ...

How to export gridview selected rows by checkbox to a excel file?
I have the code for exporting all the data on the gridview, but how do i make it to export only the slected rows with checkbox? Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click For Each row As GridViewRow In gvManagerList.Rows ' Access the CheckBox Dim cb As CheckBox = row.FindControl("cbSelect") Dim productID As Integer = Convert.ToInt32(gvManagerList.DataKeys(row.RowIndex).Value) Next If gvManagerList.Rows.Count.ToString + 1 gvMan...

Page doesn't move to top of the page when user select page 2/3 from bottom of the page
Hi, I have aspx page with pagination at bottom which show Page 1 ,2 ,3 ..etc. When user selects Page 2 or 3 , user goes to page 2 but stays at bottom of the page. I want after he hits page 2 he should move to top of the page after page refresh. How can i do this. Please help me with this. Thanks!!      Add to your page where you want the page to open to: <a id="PageTop" name="PageTop"></a> Add this JavaScript to the page:<script type="text/javascript"><!--window.onload = function (){ window.location.ha...

selecting row in gridview by clicking anywhere in row (not just on 'select' link)
Hi there- I would like my gridview to behave such that a click anywhere in the (whole length of the) row would act just like clicking the "select" column link. Anyone have any code or suggestions?   You could use: ( but you would also need to disable event validation ) <%@ Page Language="VB" EnableEventValidation="false"%> Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes.Add("onclick", "javascript:__doPostBack('GridView1','select$" &...

DataGrid: Select All checkbox to select items in all pages of Datagrid .
Hi, I want to select all checkboxes in a datagrid in all pages by clicking on header checkbox.Select all option is not propogating in Pages .I have to select all items of datagrid ,Then choose few items (50 out of 400 items) to be unchecked and submit for deletion. I used a very common implementation to select checkboxes .. Please do reply ASAP. Appreciate your help...

Web resources about - Gridview paging enabled. Has checkbox to select the row . If user select the checkbox on one page and move to 2nd page to select the rows there also to export the selected rows to excel. But doing so -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/29/2015 1:12:48 PM