View Light

DataGrid Hyperlink - How to put selected item on URL string

Say you've got a Unique ID/Primary Key value that identifies each record being shown on the datagrid. You want to have a hyperlink on each datarow that will link to another page, and pass along the selected ID of the record. How do you 'grab' that ID field and put it into the URL String as a request.querystring type parameter?

Very easy, just a bit obtuse:

Let's say your ID field is RecordNum, and you want to refer to it in the querystring as ID, make sure you are returning the ID field in the query you are using to populate the datagrid. Also, the name of the page that you are wanting to link to (and pass the ID value to) for purposes of this example is ViewEditDetails.aspx.

In the 'Text Field' box, you'll put the name of the datarow field that will show as the text of the hyperlink.

In the 'URL Field' box, put the name of the field that contains the Unique ID for the record. (So for purposes of the example, put 'ID' there [Without the quotes])

The part that makes the ID value show up in the URL querystring is in the 'URL format string' field, put 'ViewEditDetails.aspx?ID={0}' [again without the quotes] - Since we put 'ID' in the URL Field box, the value of the ID field will replace the '{0}' part of the URL format string.

You can now build the ViewEditDetails.aspx page, and obtain the passed value of the ID parameter as PassedValue = Request.QueryString("ID")

Enjoy, hope this helps!
Reply
Replies:
11/24/2006 5:17:19 AM
This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: http://www.law.cornell.edu/uscode/17/107.shtml . If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.