This post originated from an RSS feed registered with .NET Buzz
by Doug Thews.
Original Post: Creating Dynamic Hyperlinks in a Data Grid
Feed Title: IlluminatiLand
Feed URL: http://apps5.oingo.com/apps/domainpark/domainpark.cgi?client=netw8744&s=JETBRAINS.COM
Feed Description: A technology blog for people enlightened enough to think for themselves
In my HomeInventory application, I put my books into a data grid (with action buttons - see my earlier post. I wanted to include the ISBN, but also have it clickable to the Amazon.com site and pop right to that book.
The way I do it is by using a bound column to bind the ISBN number from the database. Then I use the ItemDataBound event for the data grid, which will get fired for every row bind done in the grid. Once I'm there, I intercept event calls who's ListItemType is either Item or AlternatingItem (row data instead of headers, footers, or pagers). I replace the cell's text property with an HTML anchor to the Amazon.com page for that book (which can be made by concatenating a specific Amazon URL with the ISBN), and then the original text property.
Here's the code I use for my ItemDataBound event (eliminated my formatting code for paging, headers, and footers from the original HomeInventory application for example purposes):
Dim conDblQuote As String = Chr(34)
Protected Sub DataGrid1_ItemDataCreated(ByVal sender As System.Object,_
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)_
Handles DataGrid1.ItemDataBound
Dim Cell As TableCell
Dim strOldString As String