Click here to Skip to main content
15,889,838 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
for example I have a gridview of 5 rows in that i am selecting 2 rows using checkbox and what i want is i need to display these selected 2 rows of gridview in another page in another gridview.

i need to display selected data(using checkbox) of gridview1 of one page in another page using different gridview ie gridview2.

plz help me out.

One important thing is i dont want to redirect directly to second page instead it should be stored in second page & after running second page i should display those selected data rows.
Posted
Updated 26-Mar-15 19:59pm
v2
Comments
Thanks7872 26-Mar-15 6:19am    
Help you with what? What have you tried?
Deeepakk 26-Mar-15 6:30am    
i have a gridview with 5 rows i am selecting 2 rows and i want theses selected 2 rows to be displayed in different page.
Thanks7872 26-Mar-15 6:32am    
This is already mentioned in the question. No need to repeat it. What have you tried so far. Post the code and point out the issue. Have you tried something using google?
Deeepakk 26-Mar-15 6:41am    
i am able to retrieve data into gridview and select rows....all i want is display those selected rows in different page with different gridview.

ie pass the selected data from gridview1 of page1 to gridview2 of page2..
i guess u ll give me the solution
Sinisa Hajnal 26-Mar-15 7:29am    
Either save selected primary keys and retrieve them on the second page or save whole rows and simply blindly display whatevers saved. What is the problem?

http://www.aspsnippets.com/Articles/Pass-Selected-Row-of-ASPNet-GridView-control-to-another-Page.aspx

Checkout
 
Share this answer
 
v3
Upon button click, create a new DataTable (called "dtSelected") with columns to store the data from checked rows of the first data table. Then you have 2 options:
1. Store this "dtSelected" in a session variable, followed by a Response.Redirect to the new page (called "GridViewPage2"), like this
Session["dt"] = dt;
Response.Redirect("GridViewPage2.aspx");

or
2. Store this "dtSelected" in a Context.Item collection then do a Server.Transfer to the new page, like this:
C#
Context.Items.Add("dt", dt);
Server.Transfer("GridViewPage2.aspx");

Next, on the Page_Load of the new page, do something like this:
C#
if (!this.IsPostBack)
{
    /*
    // option 1
    if (Session["dtSelected"] != null)
    {
        gvSelected.DataSource = Session["dtSelected"];
        gvSelected.DataBind();
    }
    */
    // option 2
    if (Context.Items["dtSelected"] != null)
    {
        gvSelected.DataSource = (DataTable)Context.Items["dtSelected"];
        gvSelected.DataBind();
    }
}

Which option to adopt? Decide for yourself after reading Difference Between Response.Redirect() and Server.Transfer() Methods in ASP.NET[^].
 
Share this answer
 
v3
Comments
Thanks7872 26-Mar-15 8:06am    
And how that link is related to this question? What if user selected too many rows? Who knows how many records are there in gridview? Did you consider performance?
Sinisa Hajnal 26-Mar-15 9:01am    
Rohan, the link is relevant for deciding which of two options to take. And performance isn't an issue here if he has to do it.

Personally, I would keep only row IDs in a session and retrieve the data from the database in that second page.
Deeepakk 27-Mar-15 5:20am    
how do u get the row ID's from gridview..
Sinisa Hajnal 27-Mar-15 8:06am    
You keep it in a hidden field (I'm using ID in general sense of row identification) you actually need primary key of the data so you can retrieve the table based on saved keys.
Peter Leow 27-Mar-15 10:20am    
Use DataKeyNames as shown in http://www.dotnetcurry.com/showarticle.aspx?ID=291

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900