473,839 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding Hyperlinkcolumn

I have a Datagrid with a column:

<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>

I can find the row that I am interested in by doing the following:

For each oGridItem as DataGridItem in DataGrid1.items
pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
if pidLabel.Text = 54 then
Do something
end if
next

But I want to make this text for this column a different color. The problem
is that I have no way to find it. There is no ID for this so I can't do a
findControl to get it.

Is there a way to find the control and change the color?

If I could find it I would do something like:

Answer.ForeColo r = System.Drawing. Color.Yellow

Thanks,

Tom
Nov 19 '05 #1
10 1759
Hi Tom,

I'd take a different approach, using a template column and a helper
function.

Pass the PositionID to the helper function and get back a CSS class string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
I have a Datagrid with a column:

<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>

I can find the row that I am interested in by doing the following:

For each oGridItem as DataGridItem in DataGrid1.items
pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
if pidLabel.Text = 54 then
Do something
end if
next

But I want to make this text for this column a different color. The
problem is that I have no way to find it. There is no ID for this so I
can't do a findControl to get it.

Is there a way to find the control and change the color?

If I could find it I would do something like:

Answer.ForeColo r = System.Drawing. Color.Yellow

Thanks,

Tom


Nov 19 '05 #2
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:e4******** ******@TK2MSFTN GP14.phx.gbl...
Hi Tom,

I'd take a different approach, using a template column and a helper
function.
I like the idea, as it means I don't have to go through the items to find
the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the color
doesn't change at all. In my grid the 3rd row has the PositionID as 54.

It actually does seem to be working as the viewsource shows the classes set
to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;" <HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"
DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}"
/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}" />
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

..theOrange {
color:orange;
}
..blueclass {color:blue}
..redclass {color:red}
..thankYouMessa ge {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0" border="1"
id="DataGrid1" style="margin: 5px 5px 5px 5px; padding: 5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s" href="AddNewPos itions.aspx?Pos itionID=52">Web
Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s" href="AddNewPos itions.aspx?Pos itionID=29">WAN
Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">DTIF</font></td><td align="Center" width="10%"><fo nt
face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass " href="AddNewPos itions.aspx?Pos itionID=54">Thi s
is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
*************** *************** *************** *************** *************** ***************

As you can see the the 1st <a> tags in each row have the correct class, but
the color is not changing.

Thanks,

Tom
Pass the PositionID to the helper function and get back a CSS class
string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
I have a Datagrid with a column:

<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>

I can find the row that I am interested in by doing the following:

For each oGridItem as DataGridItem in DataGrid1.items
pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
if pidLabel.Text = 54 then
Do something
end if
next

But I want to make this text for this column a different color. The
problem is that I have no way to find it. There is no ID for this so I
can't do a findControl to get it.

Is there a way to find the control and change the color?

If I could find it I would do something like:

Answer.ForeColo r = System.Drawing. Color.Yellow

Thanks,

Tom

Nov 19 '05 #3
Actually, as posted, it does seem to work. If I take out the link to my css
file and just put in the 2 classes inline - it does change the colors
correctly. I assume that something in my .css file is causing the problem.
I am looking into that now and will let you know what the problem was.

Other than that, it seems to work great.

Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uf******** ******@TK2MSFTN GP10.phx.gbl...
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:e4******** ******@TK2MSFTN GP14.phx.gbl...
Hi Tom,

I'd take a different approach, using a template column and a helper
function.


I like the idea, as it means I don't have to go through the items to find
the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the
color doesn't change at all. In my grid the 3rd row has the PositionID as
54.

It actually does seem to be working as the viewsource shows the classes
set to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;"
>

<HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"

DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}" />
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}" />
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

.theOrange {
color:orange;
}
.blueclass {color:blue}
.redclass {color:red}
.thankYouMessag e {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0"
border="1" id="DataGrid1" style="margin: 5px 5px 5px 5px; padding: 5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=52">Web Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">DTIF</font></td><td align="Center" width="10%"><fo nt
face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass "
href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
************** *************** *************** *************** *************** *************** *

As you can see the the 1st <a> tags in each row have the correct class,
but the color is not changing.

Thanks,

Tom

Pass the PositionID to the helper function and get back a CSS class
string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
I have a Datagrid with a column:

<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>

I can find the row that I am interested in by doing the following:

For each oGridItem as DataGridItem in DataGrid1.items
pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
if pidLabel.Text = 54 then
Do something
end if
next

But I want to make this text for this column a different color. The
problem is that I have no way to find it. There is no ID for this so I
can't do a findControl to get it.

Is there a way to find the control and change the color?

If I could find it I would do something like:

Answer.ForeColo r = System.Drawing. Color.Yellow

Thanks,

Tom


Nov 19 '05 #4
"tshad" <ts**********@f tsolutions.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Actually, as posted, it does seem to work. If I take out the link to my
css file and just put in the 2 classes inline - it does change the colors
correctly. I assume that something in my .css file is causing the
problem. I am looking into that now and will let you know what the problem
was.

Other than that, it seems to work great.

I found the problem, but not sure why it is happening.

Here is the pertinant part of my css file.
*************** *************** *************
<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link {
color:#4AAABD;
}
a:active {
color:#4AAABD;
}
..blueclass {color:blue}
..redclass {color:red}
</style>
*************** *************** *************

I have my links set to display as Teal.

What is happening is that the links in my css file are NOT being overwritten
by the class in the <a> tag.

<a class="redclass " href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a>

I would have thought that the color in the css file would work for all links
that didn't specifically specifiy a color.

I assume I am wrong here.

You can see the differences in these 2 links (The first has the Teal in the
style and the 2nd does not).

http://www.payrollworkshop.com/samples/testClass1.htm

http://www.payrollworkshop.com/samples/testClass2.htm

Tom
Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uf******** ******@TK2MSFTN GP10.phx.gbl...
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:e4******** ******@TK2MSFTN GP14.phx.gbl...
Hi Tom,

I'd take a different approach, using a template column and a helper
function.


I like the idea, as it means I don't have to go through the items to find
the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the
color doesn't change at all. In my grid the 3rd row has the PositionID
as 54.

It actually does seem to be working as the viewsource shows the classes
set to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;"
>

<HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"

DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}" />
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}" />
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

.theOrange {
color:orange;
}
.blueclass {color:blue}
.redclass {color:red}
.thankYouMessag e {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0"
border="1" id="DataGrid1" style="margin: 5px 5px 5px 5px; padding: 5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=52">Web Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">DTIF</font></td><td align="Center" width="10%"><fo nt
face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass "
href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
************* *************** *************** *************** *************** *************** **

As you can see the the 1st <a> tags in each row have the correct class,
but the color is not changing.

Thanks,

Tom

Pass the PositionID to the helper function and get back a CSS class
string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
I have a Datagrid with a column:

<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>

I can find the row that I am interested in by doing the following:

For each oGridItem as DataGridItem in DataGrid1.items
pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
if pidLabel.Text = 54 then
Do something
end if
next

But I want to make this text for this column a different color. The
problem is that I have no way to find it. There is no ID for this so I
can't do a findControl to get it.

Is there a way to find the control and change the color?

If I could find it I would do something like:

Answer.ForeColo r = System.Drawing. Color.Yellow

Thanks,

Tom



Nov 19 '05 #5
Hi Tom,

Another thing you could try is narrowing down the a:link which is overriding
the class:

<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link.blueclas s {
color:blue;
}
a:link.redclass {
color:red;
}
a:active {
color:#4AAABD;
}

</style>

Ken

"tshad" <ts**********@f tsolutions.com> wrote in message
news:O%******** ********@TK2MSF TNGP14.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Actually, as posted, it does seem to work. If I take out the link to my
css file and just put in the 2 classes inline - it does change the colors
correctly. I assume that something in my .css file is causing the
problem. I am looking into that now and will let you know what the
problem was.

Other than that, it seems to work great.


I found the problem, but not sure why it is happening.

Here is the pertinant part of my css file.
*************** *************** *************
<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link {
color:#4AAABD;
}
a:active {
color:#4AAABD;
}
.blueclass {color:blue}
.redclass {color:red}
</style>
*************** *************** *************

I have my links set to display as Teal.

What is happening is that the links in my css file are NOT being
overwritten by the class in the <a> tag.

<a class="redclass " href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a>

I would have thought that the color in the css file would work for all
links that didn't specifically specifiy a color.

I assume I am wrong here.

You can see the differences in these 2 links (The first has the Teal in
the style and the 2nd does not).

http://www.payrollworkshop.com/samples/testClass1.htm

http://www.payrollworkshop.com/samples/testClass2.htm

Tom
Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uf******** ******@TK2MSFTN GP10.phx.gbl...
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:e4******** ******@TK2MSFTN GP14.phx.gbl...
Hi Tom,

I'd take a different approach, using a template column and a helper
function.

I like the idea, as it means I don't have to go through the items to
find the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the
color doesn't change at all. In my grid the 3rd row has the PositionID
as 54.

It actually does seem to be working as the viewsource shows the classes
set to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;"
>
<HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana,
Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"

DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}" />
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}"
/>
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

.theOrange {
color:orange;
}
.blueclass {color:blue}
.redclass {color:red}
.thankYouMessag e {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0"
border="1" id="DataGrid1" style="margin: 5px 5px 5px 5px; padding:
5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=52">Web Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems
</font></td><td align="Center" width="10%"><fo nt face="Verdana, Arial,
Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">DTIF</font></td><td align="Center"
width="10%"><fo nt face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass "
href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems
</font></td><td align="Center" width="10%"><fo nt face="Verdana, Arial,
Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
************ *************** *************** *************** *************** *************** ***

As you can see the the 1st <a> tags in each row have the correct class,
but the color is not changing.

Thanks,

Tom

Pass the PositionID to the helper function and get back a CSS class
string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
>I have a Datagrid with a column:
>
> <asp:HyperLinkC olumn
> DataTextField=" JobTitle"
> DataNavigateUrl Field="Position ID"
>
> DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
> HeaderText="Job Title"
> Visible="True"
> SortExpression= "JobTitle"/>
>
> I can find the row that I am interested in by doing the following:
>
> For each oGridItem as DataGridItem in DataGrid1.items
> pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
> if pidLabel.Text = 54 then
> Do something
> end if
> next
>
> But I want to make this text for this column a different color. The
> problem is that I have no way to find it. There is no ID for this so
> I can't do a findControl to get it.
>
> Is there a way to find the control and change the color?
>
> If I could find it I would do something like:
>
> Answer.ForeColo r = System.Drawing. Color.Yellow
>
> Thanks,
>
> Tom
>
>




Nov 19 '05 #6
Try this one instead... it keeps the colour of your "non-class" links:

<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link.blueclas s {
color:blue;
}
a:link.redclass {
color:red;
}
a:link {
color:#4AAABD;
}

a:active {
color:#4AAABD;
}

</style>

"tshad" <ts**********@f tsolutions.com> wrote in message
news:O%******** ********@TK2MSF TNGP14.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Actually, as posted, it does seem to work. If I take out the link to my
css file and just put in the 2 classes inline - it does change the colors
correctly. I assume that something in my .css file is causing the
problem. I am looking into that now and will let you know what the
problem was.

Other than that, it seems to work great.


I found the problem, but not sure why it is happening.

Here is the pertinant part of my css file.
*************** *************** *************
<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link {
color:#4AAABD;
}
a:active {
color:#4AAABD;
}
.blueclass {color:blue}
.redclass {color:red}
</style>
*************** *************** *************

I have my links set to display as Teal.

What is happening is that the links in my css file are NOT being
overwritten by the class in the <a> tag.

<a class="redclass " href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a>

I would have thought that the color in the css file would work for all
links that didn't specifically specifiy a color.

I assume I am wrong here.

You can see the differences in these 2 links (The first has the Teal in
the style and the 2nd does not).

http://www.payrollworkshop.com/samples/testClass1.htm

http://www.payrollworkshop.com/samples/testClass2.htm

Tom
Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uf******** ******@TK2MSFTN GP10.phx.gbl...
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:e4******** ******@TK2MSFTN GP14.phx.gbl...
Hi Tom,

I'd take a different approach, using a template column and a helper
function.

I like the idea, as it means I don't have to go through the items to
find the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the
color doesn't change at all. In my grid the 3rd row has the PositionID
as 54.

It actually does seem to be working as the viewsource shows the classes
set to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;"
>
<HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana,
Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial, Helvetica,
sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"
DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"

DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}" />
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}"
/>
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

.theOrange {
color:orange;
}
.blueclass {color:blue}
.redclass {color:red}
.thankYouMessag e {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0"
border="1" id="DataGrid1" style="margin: 5px 5px 5px 5px; padding:
5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=52">Web Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems
</font></td><td align="Center" width="10%"><fo nt face="Verdana, Arial,
Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">DTIF</font></td><td align="Center"
width="10%"><fo nt face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass "
href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems
</font></td><td align="Center" width="10%"><fo nt face="Verdana, Arial,
Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
************ *************** *************** *************** *************** *************** ***

As you can see the the 1st <a> tags in each row have the correct class,
but the color is not changing.

Thanks,

Tom

Pass the PositionID to the helper function and get back a CSS class
string.

Watch for bad linebreaks in the following code...

<style>
.blueclass {color:blue}
.redclass {color:red}
</style>

<asp:datagrid id="DataGrid1" runat="server">
<columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%#
GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container,
"DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataS ource = CreateDataSourc e()
DataGrid1.DataB ind()
End If
End Sub

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
If inVal = 3 Then
Return "redclass"
End If
Return "blueclass"
End Function

Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("PositionID ", GetType(Int32)) )
dt.Columns.Add( New DataColumn _
("JobTitle", 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 4
dr = dt.NewRow()
dr(0) = i
dr(1) = "Jobname" + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSour ce

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
"tshad" <ts**********@f tsolutions.com> wrote in message
news:OL******** ******@TK2MSFTN GP14.phx.gbl...
>I have a Datagrid with a column:
>
> <asp:HyperLinkC olumn
> DataTextField=" JobTitle"
> DataNavigateUrl Field="Position ID"
>
> DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
> HeaderText="Job Title"
> Visible="True"
> SortExpression= "JobTitle"/>
>
> I can find the row that I am interested in by doing the following:
>
> For each oGridItem as DataGridItem in DataGrid1.items
> pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
> if pidLabel.Text = 54 then
> Do something
> end if
> next
>
> But I want to make this text for this column a different color. The
> problem is that I have no way to find it. There is no ID for this so
> I can't do a findControl to get it.
>
> Is there a way to find the control and change the color?
>
> If I could find it I would do something like:
>
> Answer.ForeColo r = System.Drawing. Color.Yellow
>
> Thanks,
>
> Tom
>
>




Nov 19 '05 #7
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:eu******** *****@TK2MSFTNG P15.phx.gbl...
Try this one instead... it keeps the colour of your "non-class" links:

<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link.blueclas s {
color:blue;
}
a:link.redclass {
color:red;
}
a:link {
color:#4AAABD;
}

a:active {
color:#4AAABD;
}

</style>
This works great. Just what I was looking for (except Mozilla seems to have
a problem with it).

I assume this is some bug in Mozilla (but it isn't consistant).

If you look at http://www.payrollworkshop.com/Samples/testClass4.htm, you
should see that it work fine in IE and Firefox.

In Mozilla (and Netscape 7.0), it seems to not like the 3rd row and even
though it uses the same class, it shows as Teal and not as blue as it
should.

In my other test, I actually had about 10 rows that did this.

Not sure what is causing it - I do have to figure it out as I assume some
users will be using these browsers.

I assume that the original styles ( .blueclass {color:blue} and .redclass
{color:red}) didn't work as they were not for links.

Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:O%******** ********@TK2MSF TNGP14.phx.gbl. ..
"tshad" <ts**********@f tsolutions.com> wrote in message
news:Od******** ******@TK2MSFTN GP09.phx.gbl...
Actually, as posted, it does seem to work. If I take out the link to my
css file and just put in the 2 classes inline - it does change the
colors correctly. I assume that something in my .css file is causing
the problem. I am looking into that now and will let you know what the
problem was.

Other than that, it seems to work great.


I found the problem, but not sure why it is happening.

Here is the pertinant part of my css file.
*************** *************** *************
<style type="text/css">
a {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:10px;
}
a:visited {
color:#4AAABD;
}
a:link {
color:#4AAABD;
}
a:active {
color:#4AAABD;
}
.blueclass {color:blue}
.redclass {color:red}
</style>
*************** *************** *************

I have my links set to display as Teal.

What is happening is that the links in my css file are NOT being
overwritten by the class in the <a> tag.

<a class="redclass " href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a>

I would have thought that the color in the css file would work for all
links that didn't specifically specifiy a color.

I assume I am wrong here.

You can see the differences in these 2 links (The first has the Teal in
the style and the 2nd does not).

http://www.payrollworkshop.com/samples/testClass1.htm

http://www.payrollworkshop.com/samples/testClass2.htm

Tom
Thanks,

Tom

"tshad" <ts**********@f tsolutions.com> wrote in message
news:uf******** ******@TK2MSFTN GP10.phx.gbl...
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in
message news:e4******** ******@TK2MSFTN GP14.phx.gbl...
> Hi Tom,
>
> I'd take a different approach, using a template column and a helper
> function.

I like the idea, as it means I don't have to go through the items to
find the correct one. This is much cleaner.

But I can't seem to get it to change the color.

I just added your column into my Datagrid, which works fine. But the
color doesn't change at all. In my grid the 3rd row has the PositionID
as 54.

It actually does seem to be working as the viewsource shows the classes
set to blue and red respectively (3rd one being red).

Here is the Datagrid I am using (the 1st column is the one you set up -
which works fine):

*************** *************** *************** *************** *************** *************** *
<asp:DataGrid AllowPaging="fa lse"
AllowSorting="T rue"
AutoGenerateCol umns="false"
CellPadding="3"
CellSpacing="0"
ID="DataGrid1"
runat="server"
ShowFooter="fal se"
ShowHeader="tru e"
OnSortCommand=" SortDataGrid"
border="0"
style="margin: 5px 5px 5px 5px; padding: 5px;"
>
<HeaderStyle HorizontalAlign ="center" BackColor="#c0e dee"
ForeColor="#2FA BAD" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F 2F2" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingIte mStyle BackColor="#E5E 5E5" Font-Name="Verdana,
Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign ="center" BackColor="#E8E BFD"
ForeColor="#3D3 DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif"
Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="whit e" Font-Name="Verdana, Arial,
Helvetica, sans-serif" Font-Size="smaller" />
<Columns>
<asp:templateco lumn HeaderText="Job Title">
<itemtemplate >
<asp:HyperLin k runat="server"
CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'
Text='<%# DataBinder.Eval (Container, "DataItem.JobTi tle") %>'
NavigateUrl='<% # DataBinder.Eval (Container,
"DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
</asp:hyperlink>
</itemtemplate>
</asp:templatecol umn>
<asp:HyperLinkC olumn
DataTextField=" JobTitle"
DataNavigateUrl Field="Position ID"

DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
HeaderText="Job Title"
Visible="True"
SortExpression= "JobTitle"/>
<asp:BoundColum n DataField="Post edData"
HeaderText="Dat e Posted"
ReadOnly="true"
Visible="True"
SortExpression= "DatePosted "/>
<asp:BoundColum n DataField="Comp any"
HeaderText="Com pany"
ReadOnly="true"
Visible="True"
SortExpression= "Company"/>
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Scr een Questions"
Text="Screen"

DataNavigateUrl FormatString="a ddScreenQuestio ns.aspx?Positio nID={0}" />
<asp:HyperLinkC olumn DataNavigateUrl Field="Position ID"
ItemStyle-Width="10%"
ItemStyle-HorizontalAlign ="Center" HeaderText="Tes t Questions"
Text="Test"
DataNavigateUrl FormatString="a ddSkillstest.as px?PositionID={ 0}"
/>
<asp:TemplateCo lumn visible="false" >
<ItemTemplate >
<asp:Label id="PositionID " runat="server" Text='<%#
DataBinder.Eval (Container, "DataItem.Posit ionID") %>'>
</asp:Label>
</ItemTemplate>
</asp:templateCol umn>
</Columns>
</asp:DataGrid>
*************** *************** *************** *************** *************** *************** *

Here is the GetCSSClass:

Public Function GetCSSClass _
(ByVal inVal As Integer) As String
trace.warn("in GetCSSClass inVal = " & inVal)
If inVal = 54 Then
Return "redclass"
End If
Return "blueclass"
End Function

Here is the CSS defs:

.theOrange {
color:orange;
}
.blueclass {color:blue}
.redclass {color:red}
.thankYouMessag e {
color: Black;
font-size: 14px;
font-weight: bold;
font-family:Verdana, Arial, Helvetica, sans-serif;
}

And the rendered code:

*************** *************** *************** *************** *************** **************
<table cellspacing="0" cellpadding="3" rules="all" border="0"
border="1" id="DataGrid1" style="margin: 5px 5px 5px 5px; padding:
5px;">
<tr align="Center" bgcolor="#C0EDE E">
<td><font face="Verdana, Arial, Helvetica, sans-serif"
color="#2FABAD" ><b>Job Title</b></font></td><td><font face="Verdana,
Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl0','')">< font
color="#2FABAD" >Job Title</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl1','')">< font
color="#2FABAD" >Date Posted</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b><a
href="javascrip t:__doPostBack( 'DataGrid1$_ctl 1$_ctl2','')">< font
color="#2FABAD" >Company</font></a></b></font></td><td><font
face="Verdana, Arial, Helvetica, sans-serif" color="#2FABAD" ><b>Screen
Questions</b></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif" color="#2FABAD" ><b>Test Questions</b></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=52">Web Developer Senior</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=52">Web Developer
Senior</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">14Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=52"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=52">Test</a></font></td>

</tr><tr bgcolor="#E5E5E 5">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="blueclas s"
href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware Technician</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=29">WAN Hardware
Technician</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">09Mar05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">DTIF</font></td><td align="Center"
width="10%"><fo nt face="Verdana, Arial, Helvetica, sans-serif"><a
href="addScreen Questions.aspx? PositionID=29"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=29">Test</a></font></td>

</tr><tr bgcolor="#F2F2F 2">
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<a class="redclass "
href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my test</a>
</font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif"><a href="AddNewPos itions.aspx?Pos itionID=54">Thi s is my
test</a></font></td><td><font face="Verdana, Arial, Helvetica,
sans-serif">20Apr05</font></td><td><font face="Verdana, Arial,
Helvetica, sans-serif">Cro-Magnon Systems </font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addScreen Questions.aspx? PositionID=54"> Screen</a></font></td><td
align="Center" width="10%"><fo nt face="Verdana, Arial, Helvetica,
sans-serif"><a
href="addSkills test.aspx?Posit ionID=54">Test</a></font></td>
*********** *************** *************** *************** *************** *************** ****

As you can see the the 1st <a> tags in each row have the correct class,
but the color is not changing.

Thanks,

Tom
>
> Pass the PositionID to the helper function and get back a CSS class
> string.
>
> Watch for bad linebreaks in the following code...
>
> <style>
> .blueclass {color:blue}
> .redclass {color:red}
> </style>
>
> <asp:datagrid id="DataGrid1" runat="server">
> <columns>
> <asp:templateco lumn HeaderText="Job Title">
> <itemtemplate >
> <asp:HyperLin k runat="server"
> CssClass='<%#
> GetCSSClass(Dat aBinder.Eval(Co ntainer, "DataItem.Posit ionID")) %>'
> Text='<%# DataBinder.Eval (Container,
> "DataItem.JobTi tle") %>'
> NavigateUrl='<% # DataBinder.Eval (Container,
> "DataItem.Posit ionID", "AddNewPosition s.aspx?Position ID={0}") %>'>
> </asp:hyperlink>
> </itemtemplate>
> </asp:templatecol umn>
> </columns>
> </asp:datagrid>
>
>
> Private Sub Page_Load _
> (ByVal sender As System.Object, _
> ByVal e As System.EventArg s) Handles MyBase.Load
> If Not IsPostBack Then
> DataGrid1.DataS ource = CreateDataSourc e()
> DataGrid1.DataB ind()
> End If
> End Sub
>
> Public Function GetCSSClass _
> (ByVal inVal As Integer) As String
> If inVal = 3 Then
> Return "redclass"
> End If
> Return "blueclass"
> End Function
>
> Function CreateDataSourc e() As DataTable
> Dim dt As New DataTable
> Dim dr As DataRow
> dt.Columns.Add( New DataColumn _
> ("PositionID ", GetType(Int32)) )
> dt.Columns.Add( New DataColumn _
> ("JobTitle", 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 4
> dr = dt.NewRow()
> dr(0) = i
> dr(1) = "Jobname" + i.ToString()
> dr(2) = 1.23 * (i + 1)
> dr(3) = (i = 4)
> dt.Rows.Add(dr)
> Next i
> Return dt
> End Function 'CreateDataSour ce
>
> Let us know if this helps?
>
> Ken
> Microsoft MVP [ASP.NET]
> Toronto
>
>
> "tshad" <ts**********@f tsolutions.com> wrote in message
> news:OL******** ******@TK2MSFTN GP14.phx.gbl...
>>I have a Datagrid with a column:
>>
>> <asp:HyperLinkC olumn
>> DataTextField=" JobTitle"
>> DataNavigateUrl Field="Position ID"
>>
>> DataNavigateUrl FormatString="A ddNewPositions. aspx?PositionID ={0}"
>> HeaderText="Job Title"
>> Visible="True"
>> SortExpression= "JobTitle"/>
>>
>> I can find the row that I am interested in by doing the following:
>>
>> For each oGridItem as DataGridItem in DataGrid1.items
>> pidLabel = CType(oGridItem .FindControl("P ositionID"),Lab el)
>> if pidLabel.Text = 54 then
>> Do something
>> end if
>> next
>>
>> But I want to make this text for this column a different color. The
>> problem is that I have no way to find it. There is no ID for this so
>> I can't do a findControl to get it.
>>
>> Is there a way to find the control and change the color?
>>
>> If I could find it I would do something like:
>>
>> Answer.ForeColo r = System.Drawing. Color.Yellow
>>
>> Thanks,
>>
>> Tom
>>
>>
>


Nov 19 '05 #8
Hi Tom,

Glad to hear it helps. You might want to do a search to see if there's a way
to get it to work in Mozilla. I don't know anything about that browser.

See you later!

Ken
This works great. Just what I was looking for (except Mozilla seems to
have a problem with it).

I assume this is some bug in Mozilla (but it isn't consistant).

If you look at http://www.payrollworkshop.com/Samples/testClass4.htm, you
should see that it work fine in IE and Firefox.

In Mozilla (and Netscape 7.0), it seems to not like the 3rd row and even
though it uses the same class, it shows as Teal and not as blue as it
should.

In my other test, I actually had about 10 rows that did this.

Not sure what is causing it - I do have to figure it out as I assume some
users will be using these browsers.

I assume that the original styles ( .blueclass {color:blue} and .redclass
{color:red}) didn't work as they were not for links.

Thanks,

Tom


Nov 19 '05 #9
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:uw******** ******@TK2MSFTN GP10.phx.gbl...
Hi Tom,

Glad to hear it helps. You might want to do a search to see if there's a
way to get it to work in Mozilla. I don't know anything about that
browser.
Actually, it wasn't a browser issue. It was that I needed to also change
the visited and active links. What was happening was that once I visited
the link, it went to visited (which wasn't set up for blue and red) so it
took the default - Teal.

BTW, is there a way to have it only take red if the positionID is equal some
number and the rest stay the default color? Using the following:

CssClass='<%# GetCSSClass(Dat aBinder.Eval(Co ntainer,
"DataItem.Posit ionID")) %>'

Would I do the return as just:

Return

instead of

Return "blueclass"

or would that cause an error.

Thanks,

Tom
See you later!

Ken
This works great. Just what I was looking for (except Mozilla seems to
have a problem with it).

I assume this is some bug in Mozilla (but it isn't consistant).

If you look at http://www.payrollworkshop.com/Samples/testClass4.htm, you
should see that it work fine in IE and Firefox.

In Mozilla (and Netscape 7.0), it seems to not like the 3rd row and even
though it uses the same class, it shows as Teal and not as blue as it
should.

In my other test, I actually had about 10 rows that did this.

Not sure what is causing it - I do have to figure it out as I assume some
users will be using these browsers.

I assume that the original styles ( .blueclass {color:blue} and .redclass
{color:red}) didn't work as they were not for links.

Thanks,

Tom

Nov 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4848
by: Jongmin | last post by:
Hi! I am making HyperLinkColumn in datagrid. It is simple to make the hyerlinkcolumn with one datafield. <asp:HyperLinkColumn Text="NAME" DataNavigateUrlField="NAME" DataNavigateUrlFormatString="http://www.aaa.com?Name={0}" SortExpression="NAME" />
1
1450
by: Dmitri Manushin | last post by:
Hi all, i have HyperLinkColumn in DataGrid <asp:HyperLinkColumn DataNavigateUrlField="PostID" DataNavigateUrlFormatString="http://localhost/forum/posts.aspx?id={0}" DataTextField="Subject" HeaderText="ôÅÍÁ"> This code work, but when i do next <asp:HyperLinkColumn DataNavigateUrlField="PostID" DataNavigateUrlFormatString="http://manushind/forum/posts.aspx?id={0}?page=1
3
3382
by: SStory | last post by:
I have a style sheet for my site. It has various classes in it. It has <A: styles defined for all anchor tags. I have a datagrid in ASP.NET with a stylesheet linked to the page. It defines links a yellow which is what I normally won't but in this case I want to override the link color and can't seem to do it. I set the forecolor in itemstyle prop. But it doesn't work.
3
1229
by: Morten | last post by:
Hi. After a while I finaly discovered how to use HyperLinkColumns. What I can't find is how to send mote than one "value" like page.aspx?id1&id2!!! <asp:HyperLinkColumn DataNavigateUrlField="InvoNo" DataNavigateUrlFormatString="Invo.aspx?Id={0}" DataTextField="InvoNo" HeaderText="Invo No."> <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
3
3376
by: TJS | last post by:
how can I encrypt the querystring values for a HyperLinkColumn ? in example below I would like to encrypt value for field1 ====================================================== <asp:HyperLinkColumn Text="View" DataNavigateUrlField="field1" DataNavigateUrlFormatString="page.aspx?idx={0}"></asp:HyperLinkColumn>
0
1088
by: Atif Jalal | last post by:
I am using a Datagrid control and one of its column is a 'HyperLinkColumn'. The link text for this HyperLinkColumn is sometimes beyond 100 characters. I would like to display the link on multi-line if the number of characters in the link exceed 100 characters. I tried adding the <ItemStyle> to the HyperLinkColumn tag but it did not work, the whole of the link is displayed on one line with the column width getting extended. ...
1
2829
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters in varying search criteria, hits "search", info is passed to a stored proc, results return and displayed in the datagrid. Every field in the datagrid is numeric (indicative of a certain sum or total) data but also functions as a...
1
1475
by: Craig | last post by:
I have a datagrid with a couple of columns. Right now, I'm setting assigning the dataview to the datasource. For the HyperLinkColumn.... <asp:HyperLinkColumn DataNavigateUrlField="ATTACHMENTDOWNLOADURL" Text="Download" HeaderText="Quick Links" SortExpression="FILEPATH"/> The field in the dataview is something like: "/mypath/tomyfile/hello.txt" the link gets set to http://localhost/mypath/tomyfile/hello.txt" I want the base of the...
4
2256
by: rcoco | last post by:
Hi all, I have this big problem with hyperlinks I would appriciate any help please. My web site has two datagrids on the same page. And one has a list of names of the users which are in a HyperlinkColumn. The second datagrid is for inserting data, and when a user inserts data I used 'Windows Authentication' for names in one column called Name. Now this is how it's supposed to work: When any user want to see data about a particular user...
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10587
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4487
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.