Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HyperLinks in Datagrid (visited link & unvisited link colors)

Status
Not open for further replies.

DLLHell

Programmer
May 9, 2003
69
0
0
US
If I wanted a grid where the longevity of the Visited & Unvisited colors of the hyperlinks were good only for the life of the grid until a new search were made... is there an Event that is triggered whenever a link is clicked in ASP.NET? I am thinking of modifying the HyperLink.ForeColor property at ItemDataBound time probably via cookie or txt file to that end at but not sure if there is any Event fired off. If there are better ways available I'm all ears. I am not finding any Events fired off.

Thanks.
 
dll: The ItemDataBound event is probably the one you are looking for. There are several articles floating around (some discussed here at Tek-Tips) regarding the various alterations of the DataGrid during binding of the latter, as an example:

Sub dgSites_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
'Add the OnMouseOver and OnMouseOut method to the Row of DataGrid
e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#CCFFFF'")
e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor=''")
e.Item.Cells(0).Style("cursor") = "hand"
e.Item.Cells(1).Style("cursor") = "hand"
e.Item.Cells(2).Style("cursor") = "hand"
e.Item.Cells(0).Attributes.add("onClick","return openWinSites('x" & e.Item.Cells(0).Text & "');")
e.Item.Cells(1).Attributes.add("onClick","return openWinSite('w" & e.Item.Cells(0).Text & "');")
e.Item.Cells(2).Attributes.add("onClick","return openWinSite('p" & e.Item.Cells(0).Text & "');")
e.Item.Cells(3).Attributes.add("onClick","return openWinSite('o" & e.Item.Cells(0).Text & "');")
End If
End Sub
 
Did you try applying a style on the HyperLink, instead of setting it inside the tag?
Code:
<asp:HyperLink runat=server CssClass=&quot;someStyle&quot; />
 
Hi - yes, that is how I did it. I was surprised to see that I could obtain the &quot;visited link&quot; color at ItemDataBound time, so everything worked out fine - no cookies or txt file logic needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top