Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,
I'm doing a ASP.net webapp with a gridview.
On selectedindexchanged event I want to open a new URL with the below code and pass my selected value to the back of the URL. But it dosen't Work :-(

It says that my Gridview is not defined?

How do I do that?

What I have tried:

//This code Works - opening site without any additional parameters
Response.Write("<script>window.open('http://www.mywebsite.com/products/','_blank');</script>");

//This code does not Work - opening site + selected value
Response.Write("<script>window.open('http://www.mywebsite.com/products/= ' + GridView1.SelectedRow.Cells[2].Text);</script>");
Posted
Updated 7-Jun-16 1:49am
Comments
Prateek Dalbehera 2-Jun-16 8:00am    
In the url, after /products, you should use query string, so the correct format may be like /products?paramName=paramValue
Kristian_dk 7-Jun-16 7:45am    
Thanks Prateek - you led me in the right direction :-) now it works
Prateek Dalbehera 8-Jun-16 0:58am    
Most welcome...

1 solution

Response.Redirect("~/MyNextPage.aspx?Parameter1=" + Dropdown1.SelectedItem.Value + "&Parameter2=" + Dropdown2.SelectedItem.Value + "&Parameter3=" + Dropdown3.SelectedItem.Value );
}
 
Share this answer
 
Comments
Richard Deeming 7-Jun-16 10:03am    
You should encode the values before appending them to the URL:

Response.Redirect(string.Format("~/MyNextPage.aspx?Parameter1={0}&Parameter2={1}&Parameter3={2}",
   HttpUtility.UrlEncode(Dropdown1.SelectedValue),
   HttpUtility.UrlEncode(Dropdown2.SelectedValue),
   HttpUtility.UrlEncode(Dropdown3.SelectedValue));
Prateek Dalbehera 8-Jun-16 0:58am    
Great point Richard... Always encoding is preferred because sometimes special characters would create create issues while passing from browser to server...e.g. while passing backslash(/) may create issues..
Kristian_dk 8-Jun-16 1:02am    
Thanks for tipping in Richard. I was not aware of Encoding. Good learning for me.

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