Hi Chuck,
I think your problem with CSS is that you're trying to change the class of
the whole row and not just the hyperlink.
Here's some sample code that seems to do what you want. It changes the
Cssclass attribute of the hyperlink according to the inbound value.
Let us know if this helps?
Ken
Microsoft MVP [ASP.NET]
Toronto
<!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
}
</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"
Else
hlnk.CssClass = "outclass"
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
chuckdfoster said:
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
or not. How can I accomplish this? I have tried using CSS but that
doesn't
affect what is going on in my datagrid. This is what I have so far for
formatting in my datagrid...
Sub ItemBound(ByVal sender As Object, ByVal e as DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
'check inout field, if In then font is green, if Out then font is
red
Dim strInOut as String = DataBinder.Eval(e.Item.DataItem, "inout")
If strInOut = "In" then
e.Item.ForeColor = System.Drawing.Color.Green
Else
e.Item.ForeColor = System.Drawing.Color.Red
End If
End If
End Sub
Any advice is greatly appreciated....Thanks in advance!