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!
Rating: (You must be logged in to vote)
11/24/2006 5:17:19 AM
0 Dislikes: 0