The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Creating Dynamic Hyperlinks in a Data Grid

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic    
Flat View: This topic has 0 replies on 1 page
Doug Thews

Posts: 866
Nickname: dougthews
Registered: Jul, 2003

Doug Thews is a software developer/manager for D&D Consulting Services with 18+ years of experience
Creating Dynamic Hyperlinks in a Data Grid Posted: Jul 16, 2003 11:08 PM
Reply to this message Reply

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
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Doug Thews
Latest Posts From IlluminatiLand

Advertisement
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

 Select Case e.Item.ItemType
'Row item (Item or Alternating Item)
  Case ListItemType.Item
   ' Format the ISBN to be a link to the Amazon.com book page
   ' I know column #5 is the ISBN
   Cell = e.Item.Cells(5)
   strOldString = Cell.Text
   e.Item.Cells(5).Text = _
   "
   "HREF=" & conDblQuote & "http://www.amazon.com/exec/obidos/ASIN/" & _
   strOldString.Replace("-", "").Trim & conDblQuote & ">" &_
   strOldString.Trim & "
"
  Case ListItemType.AlternatingItem
   ' Format the ISBN to be a link to the Amazon.com book page
   ' I know column #5 is the ISBN
   Cell = e.Item.Cells(5)
   strOldString = Cell.Text
   e.Item.Cells(5).Text = _
   "
   "HREF=" & conDblQuote & "http://www.amazon.com/exec/obidos/ASIN/" & _
   strOldString.Replace("-", "").Trim & conDblQuote & ">" &_
   strOldString.Trim & "
"

  ' Other types
  Case ListItemType.Header
  Case ListItemType.Footer
  Case ListItemType.Pager
  Case Else
 End Select
End Sub

Read: Creating Dynamic Hyperlinks in a Data Grid

Topic: Rockets on Prisoner Award Previous Topic    

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use