How to post data from gridview on one page to detailview on another page when select is used

I need to get data from gridview on one page to detailview on other page when I use select statement.I am able to do this on same page by using following code but not able to do this on different page

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DetailsView1.PageIndex = GridView1.SelectedIndex;
    }

 

Is it possible that when I use select in gridview on a particular page then only that row data appear on detail view of another page. please let me know asap. 


Find the Best Webhosts on Internet on http://www.besthostonline.com
0
safibaig
12/15/2007 6:46:07 PM
📁 asp.net.presentation-controls
📃 72751 articles.
⭐ 2 followers.

💬 4 Replies
👁️‍🗨️ 499 Views

You could pass the ID of the record as a querystring to the other page e.g.

 
Response.Redirect("otherpage.aspx?id=" &  GridView1.SelectedIndex)
 
Then, you can read the id in your other page by using:
Request.Querystring("id")
 

Website Design Darlington - http://mdssolutions.co.uk
http://lessthandot.com - Experts, Information, Ideas & Knowledge
http://aspnetlibrary.com - An online resource for professional ASP.NET developers


Please remember to click "Mark as Answer" on this post if it helped you

0
ca8msm
12/17/2007 8:39:33 AM

You can also use Session Variable like below

 I assumed that you have used the SELECT commandField in your GridView.
 

    protected void Button1_Click(object sender, EventArgs e)
    {
      
        for (int i = 0; i < GrdiView1.Rows.Count; i++)
        {
            if (GrdiView1.SelectedIndex == i)
            {
                String id =GrdiView1.Rows[i].Cells[1].Text; //Gets the id value in the grid based on the selected index;
                Session["Value"] = id;
                Response.Redirect("SecondPage.aspx");

            }
        }
       
    }

SecondPage.aspx

On page load you can get the value of your stored in the session variable

protected void Page_Load(object sender, EventArgs e)
{
 
    string getid = Session["Value"].ToString();

   //Now you can bind your DetailsView based on that id

}


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
12/17/2007 8:54:42 AM

Thanks for replying.

How  can  I add a new row in my gridview I want automatically  
a detailview of that row in a new page is created.


Find the Best Webhosts on Internet on http://www.besthostonline.com
0
safibaig
12/17/2007 12:13:49 PM

You're Welcome! Anyways....you can refer to this article regarding that matter

http://www.koffeekoder.com/ArticleDetails.aspx?id=98 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
0
vinz
12/18/2007 1:13:02 AM
Reply: