smitty68521
asked on
Pass values from gridview to another page
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?
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would it start out like this:
GridView1_SelectedIndexCha nged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexCha nged?
I would add my code here for the server.transfer?
GridView1_SelectedIndexCha
I would add my code here for the server.transfer?
ASKER
This is what I have tried so far:
1st page with the datagrid
Protected Sub GridView1_SelectedIndexCha nging(ByVa l sender As Object, ByVal e As System.Web.UI.WebControls. GridViewSe lectEventA rgs) Handles GridView1.SelectedIndexCha nging
Context.Items.Add("ID", SqlDataSource2.ID)
Server.Transfer("editprope rty.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.
1st page with the datagrid
Protected Sub GridView1_SelectedIndexCha
Context.Items.Add("ID", SqlDataSource2.ID)
Server.Transfer("editprope
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.
No need to add/update GridView1_SelectedindexCha nging 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="FIE LDNAME1,FI ELDNAME2" DataNavigateUrlFormatStrin g="~/PAGEN AME.aspx?Q UERYSTRING 1={0}&QUER YSTRING2={ 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.
Just add a hyperLinkFiled at the last column of the gridview as follows:->
<asp:HyperLinkField Text="Select" DataNavigateUrlFields="FIE
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.
ASKER
I done as you told me:
Hyperlink
DatanavigateUrlfield= "ID"
DatanavigateUrlFormatStrin g = "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
Hyperlink
DatanavigateUrlfield= "ID"
DatanavigateUrlFormatStrin
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
Replace value = {ID} with value = {0}
ASKER
Thanks. Right after I sent that, I realized what I was doing.
ASKER
Awesome expert