>I have a hyperlink column in my datagrid. I want my hyperlink to be green
> or red (depending on in/out status) no matter if the link has been visited
[quoted text clipped - 18 lines]
>
> Any advice is greatly appreciated....Thanks in advance!
Thank you so much for the help, but I'm still having a little problem.
I understand what you mean about changing the whole row and not just the
hyperlink. I actually want to change the whole, including the hyperlink.
It changes the entire row except for the hyperlink. I'm a little confused
about how the .inclass and .outclass works in the CSS part. I added it to
my page, but no change. I figure that I wasn't supposed to put .inclass and
.outclass,but I don't know what to put in its place. Can you help just a
little more?
<style>
.inclass {
COLOR: green; TEXT-DECORATION: none
}
.outclass {
COLOR: red; TEXT-DECORATION: none
}
</style>
Thanks again!

Signature
Chuck Foster
Programmer Analyst
Eclipsys Corporation - St. Vincent Health System
> Hi Chuck,
>
[quoted text clipped - 123 lines]
> >
> > Any advice is greatly appreciated....Thanks in advance!
Ken Cox [Microsoft MVP] - 10 Mar 2005 02:40 GMT
Hi Chuck,
Not exactly sure what you mean, but you do have to treat the row and the
hyperlink separately as far as assign the style class goes. Here, I assign
different classes to the hyperlink and the row. Maybe this is what you're
after?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>dghlnk</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<style>
.inclass {
COLOR: green; TEXT-DECORATION: none
}
.outclass {
COLOR: red; TEXT-DECORATION: none
}
.inItemclass {
COLOR: green;
}
.outItemclass {
COLOR: red;
}
</style>
</head>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templatecolumn HeaderText="In/Out">
<itemtemplate>
<asp:HyperLink ID="myhlink" runat="server"
Text='<%# DataBinder.Eval(Container, "DataItem.inout") %>' NavigateUrl='<%#
"http://www.aspalliance.com?id=" & DataBinder.Eval(Container,
"DataItem.Integervalue") %>' Target="_blank">
</asp:hyperlink>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
<p> </p>
<p> </p>
</form>
</body>
</html>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub
Private Sub DataGrid1_ItemDataBound _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemDataBound
Dim hlnk As HyperLink
If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then
Dim strInOut As String = DataBinder.Eval(e.Item.DataItem,
"inout")
hlnk = e.Item.FindControl("myhlink")
If strInOut = "In" Then
hlnk.CssClass = "inclass"
e.Item.CssClass = "inItemClass"
Else
hlnk.CssClass = "outclass"
e.Item.CssClass = "outItemClass"
End If
End If
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("inout", GetType(String)))
dt.Columns.Add(New DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
If (i Mod 2) = 0 Then
dr(1) = "In"
Else
dr(1) = "Out"
End If
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
> Thank you so much for the help, but I'm still having a little problem.
>
[quoted text clipped - 150 lines]
>> >
>> > Any advice is greatly appreciated....Thanks in advance!
David Alpert - 28 Mar 2005 22:50 GMT
> Thank you so much for the help, but I'm still having a little problem.
>
[quoted text clipped - 13 lines]
> }
> </style>
Sometimes CSS can be tricky if your HTML contains ID attributes mixed
in with CLASS attributes. ID attributes are sematically more specific
(supposed to be unique per page while CLASS attributes can occur many
times per page) and so generally take precedence.
Furthermore, CSS works with principles of inheritance and cascading,
so that if you have HTML with CLASS attributes nested inside HTML tag
with an ID attribute, those CLASS attributes can be selected and
styled separately from the same CLASS attribute outside that ID
container or inside another ID container.
Now, things get tricky in the HTML generated by ASP.NET because, so
far as i can tell, the HTML generated by ASP.NET is generally a mess.
For example, there always seem to be <span> tags with ID elements
scattered everywhere, especially in templated code:
<ul class=""><span id=""><li></li></span><span
id="><li></li></span></ul>
and this sometimes has interfered with my attempts to write clean and
simple style sheets for ASP.NET pages. Simple class rules
(.someclass) don't always seem to select "sometag" in the following
html:
<span id="long$_and$_unique$_aspnet$_clientID"><sometag
class="someclass" /></span>
Just something to consider when styling ASP.NET ....
David