Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Pass values from gridview to another page

Posted on 2008-10-20
9
Medium Priority
?
570 Views
Last Modified: 2013-11-07
I have a gridview on a membership page that has a "select" button. However, I don't want this to be the normal select that the gridview has. I want it to do a response.redirect to another page and fill another gridview there.  In short, my question is how do I perform a querystring based on what row is selected in the gridview?
0
Comment
Question by:smitty68521
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22764369
what needs to be done is that when you select the grid view row you handle the select on the same page (page having the grid view) in a suitable event (RowCommand event). In the row command event you can get the values from the grid view selected row and then create the query string and the redirect your page to the new page where you can retrieve the values from the query string and take actions accordingly
0
 
LVL 2

Accepted Solution

by:
spiderexpa earned 2000 total points
ID: 22764658
Just add a hyperlink at the last column of the gridview as follows:->

<asp:HyperLinkField Text="Select" DataNavigateUrlFields="FIELDNAME1,FIELDNAME2" DataNavigateUrlFormatString="~/PAGENAME.aspx?QUERYSTRING1={0}&QUERYSTRING2={1}"/>

Here

1. FIELDNAME1, FIELDNAME2,... are the Field names from the database OR Alias used.
2. PAGENAME.aspx is the page where you want to re-direct.
3. QUERYSTRING1, QUERYSTRING2,.... are the corresponding Querystring names.


0
 
LVL 1

Author Comment

by:smitty68521
ID: 22764682
Would it start out like this:

GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged?

I would add my code here for the server.transfer?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 1

Author Comment

by:smitty68521
ID: 22764747
This is what I have tried so far:

1st page with the datagrid

Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles GridView1.SelectedIndexChanging
        Context.Items.Add("ID", SqlDataSource2.ID)
        Server.Transfer("editproperty.aspx")

    End Sub

second page:

Label1.Text = Context.Items("ID")

When I run this, I click on the "select" button and get a windows authentication that comes up asking for a username/password.  Like it is wanting it to access the database.  I suppose I should have added this sooner.
0
 
LVL 2

Expert Comment

by:spiderexpa
ID: 22764780
No need to add/update GridView1_SelectedindexChanging  anything else in code behind for this issue. No need to use Server.Tranfer/ Response.Redirect.



Just add a hyperLinkFiled at the last column of the gridview as follows:->

<asp:HyperLinkField Text="Select" DataNavigateUrlFields="FIELDNAME1,FIELDNAME2" DataNavigateUrlFormatString="~/PAGENAME.aspx?QUERYSTRING1={0}&QUERYSTRING2={1}"/>

Here

1. FIELDNAME1, FIELDNAME2,... are the Field names from the database OR Alias used.
2. PAGENAME.aspx is the page where you want to re-direct.
3. QUERYSTRING1, QUERYSTRING2,.... are the corresponding Querystring names.
0
 
LVL 1

Author Comment

by:smitty68521
ID: 22765024
I done as you told me:

Hyperlink
DatanavigateUrlfield= "ID"
DatanavigateUrlFormatString = "editproperty.aspx?value = {ID}

On the next page I have in the gridview datasource I have the control Label1.text set to the querystring {ID}

When I run the application I get the following error:

Input string was not in a correct format
0
 
LVL 2

Expert Comment

by:spiderexpa
ID: 22765053
Replace value = {ID} with value = {0}
0
 
LVL 1

Author Comment

by:smitty68521
ID: 22765059
Thanks. Right after I sent that, I realized what I was doing.
0
 
LVL 1

Author Closing Comment

by:smitty68521
ID: 31508135
Awesome expert
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question