Set row color of a datagrid when more than one datagrid on a form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using visual studio 2005 to develop a form using c#

I have 3 datagrids on one form.

I can set the row color based on a certain value in a column. However this
color applies to all 3 datagrida. I would like to set it so that

if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to green
if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to green
if value of column 3 in datagrid 3is < 80 set to red, if >= 80set to green

No matter how I write my code I cannot seem to get the coloring to apply to
just one datagrid

My code is below:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<script runat="server">

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 100)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 70)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}

}


protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{

}

</script>

<html><!-- InstanceBegin template="/Templates/supportstats.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>HKS Medical Information Systems</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="styles.css">
<script language="JavaScript" src="common.js" type="text/JavaScript"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!--
InstanceParam name="NavAboutUsON" type="boolean" value="false" --><!--
InstanceParam name="NavSoftwareSolutionsON" type="boolean" value="false"
--><!-- InstanceParam name="NavServicesON" type="boolean" value="false"
--><!-- InstanceParam name="NavSupportON" type="boolean" value="false"
--><!-- InstanceParam name="NavNewsON" type="boolean" value="false" --><!--
InstanceParam name="NavContactON" type="boolean" value="false" -->
<script language="JavaScript">
function breadCrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) { // by Paul
Davis - http://www.kaosweaver.com
loc=window.location.toString();subs=loc.substr(loc.indexOf(base)+base.length+1).split("/");
document.write('<a href="'+getLoc(subs.length-1)+defp+'"
class="'+cStyle+'">Home</a> '+'<span class="'+dStyle+'">'+delStr+'</span> ');
a=(loc.indexOf(defp)==-1)?1:2;for (i=0;i<(subs.length-a);i++) {
subs=makeCaps(unescape(subs));
document.write('<a href="'+getLoc(subs.length-i-2)+defp+'"
class="'+cStyle+'">'+subs+'</a> '+'<span
class="'+dStyle+'">'+delStr+'</span> ');}
if (nl==1) document.write("<br>");document.write('<span
class="'+tStyle+'">'+document.title+'</span>');
}
function makeCaps(a) {
g=a.split(' ');for (l=0;l<g.length;l++)
g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
return g.join(" ");
}
function getLoc(c) {
var d="";if (c>0) for (k=0;k<c;k++) d=d+"../"; return d;
}
</script>
</head>

<body link="#6F96C6" alink="#6F96C6" vlink="#6F96C6">

<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="224"><a href="http://www.hksys.com"><img
src="images/hdr_logo.gif" alt="HKS Medical Information Systems" width="187"
height="79" border="0"></a></td>
<td width="776"><!-- InstanceBeginEditable name="Header" --><img
src="images/hdr_home.jpg" alt="" height="79" style="width: 811px"><!--
InstanceEndEditable --></td>
</tr>
</table>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#6F96C6"> </td>
<td height="25" align="RIGHT" bgcolor="#6F96C6"><table width="990"
height="23" border="0" cellpadding="0" cellspacing="0">
<form action="search/search.pl" method="GET" name="SearchSite">
<input type="hidden" name="p" value="1" /><input type="hidden"
name="lang" value="en" /><input type="hidden" name="include" value=""
/><input type="hidden" name="exclude" value="" /><input type="hidden"
name="penalty" value="0" /><input type="HIDDEN" name="mode" value="any">

</form>
</table></td>
</tr>
<tr>
<td height="8" colspan="2"><img src="images/spacer.gif" width="1"
height="8"></td>
</tr>
</table>
<table width="996" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1000" valign="TOP"><table width="1000" border="0"
cellpadding="0" cellspacing="0" bgcolor="#A4A4A5">
<tr>
<td height="1" colspan="3"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>

<td width="1000" bgcolor="#FFFFFF"><table width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" bgcolor="#6F96C6"><!-- InstanceBeginEditable
name="PageTitle" --><span class="pageTitle">Support SLA
Compliance </span><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><table width="1000" border="0" cellpadding="0"
cellspacing="0">
<tr>

<td width="1000"><!-- InstanceBeginEditable
name="PageContent" -->
<form id="form1" runat="server">
<div>
<h1>
HKS Support Statistics</h1>
<p>
Click Links for more detail,
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/priority1-main.aspx">Priority 1 </asp:HyperLink>
Issues Last Updated:</span>
</p>
<p>
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="~/priority1-graph.aspx"
Target="_blank">Graph</asp:HyperLink> </p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_24hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority1 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority1 AS Priority1_1))

"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource1" Font-Names="Arial"
ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_24hrs" HeaderText="# of Issues
Resolved Within 24hrs"

SortExpression="Number_of_tickets_closed_within_24hrs" />
<asp:BoundField DataField="% of Tickets Closed within
SLAS" HeaderText="% of Issues Resolved Within SLAs"
SortExpression="% of Tickets Closed within SLAS" />
</Columns>
</asp:GridView>
</p>
<p>
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/priority2-main.aspx">Priority 2</asp:HyperLink> Issues Last
Updated:</span></p>
<p>
<span style="font-family: Arial"> <asp:HyperLink ID="HyperLink5"
runat="server" NavigateUrl="~/priority2-graph.aspx"
Target="_blank">Graph</asp:HyperLink>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_48hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority2 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority2 AS Priority2_1))
"></asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333"
GridLines="None" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_48hrs" HeaderText="# of Issues
Resolved Within 48hrs"

SortExpression="Number_of_tickets_closed_within_48hrs" />
<asp:BoundField DataField="% of Tickets Closed
within SLAS" HeaderText="% of Issues Resolved Within SLAS"
SortExpression="% of Tickets Closed within SLAS"
/>
</Columns>
</asp:GridView>
</span>
</p>
<p>
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="~/priority3-main.aspx">Priority 3</asp:HyperLink>
Issues Last Updated:</span></p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink6" runat="server"
NavigateUrl="~/priority3-graph.aspx"
Target="_blank">Graph</asp:HyperLink></span> </p>
<p>
<span style="font-family: Arial">
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
number_of_tickets_opened, number_of_tickets_closed_within_120hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority3 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority3 AS Priority3_1))"></asp:SqlDataSource>
<asp:GridView ID="GridView3" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource3" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField DataField="number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="number_of_tickets_opened" />
<asp:BoundField
DataField="number_of_tickets_closed_within_120hrs" HeaderText="# of Issues
Resolved Within 200hrs"

SortExpression="number_of_tickets_closed_within_120hrs" />
<asp:BoundField DataField="% of Tickets Closed
within SLAS" HeaderText="% of Issues Resolved Within SLAs"
SortExpression="% of Tickets Closed within SLAS"
/>
</Columns>
</asp:GridView>
</span>
</p>

</div>
</form>
<!-- InstanceEndEditable --></td>

</tr>
</table></td>
</tr>
</table></td>
<td width="1"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>
<td height="1" colspan="3"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
</table></td>
</tr>
</table>
<table width="1000" border="0" cellpadding="8" cellspacing="0">
<tr>
<td width="1000" align="CENTER" class="footer">© 2006 HKS Medical
Information
Systems | <a href="http://web1.hksys.com/sw/" target="_blank"
class="footerLink">User
Support</a> | <a href="http://www.hksys.com/admin/" target="_blank"
class="footerLink">Client
Login</a> | <a href="default.htm" class="footerLink">Home</a></td>
</tr>
<tr>
<td bgcolor="#6F96C6"><img src="images/spacer.gif" width="1" height="10"
alt=""></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
 
Mike,

Have you considered creating a subclass of the data grid and exposing a
property which has the threshold for the value in column three? It might
make things a little easier for you.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike Baugh said:
I am using visual studio 2005 to develop a form using c#

I have 3 datagrids on one form.

I can set the row color based on a certain value in a column. However this
color applies to all 3 datagrida. I would like to set it so that

if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to
green
if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to
green
if value of column 3 in datagrid 3is < 80 set to red, if >= 80set to green

No matter how I write my code I cannot seem to get the coloring to apply
to
just one datagrid

My code is below:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<script runat="server">

protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{

}

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 100)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 70)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}

}


protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView2_SelectedIndexChanged(object sender, EventArgs
e)
{

}

</script>

<html><!-- InstanceBegin template="/Templates/supportstats.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>HKS Medical Information Systems</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="styles.css">
<script language="JavaScript" src="common.js"
type="text/JavaScript"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!--
InstanceParam name="NavAboutUsON" type="boolean" value="false" --><!--
InstanceParam name="NavSoftwareSolutionsON" type="boolean" value="false"
--><!-- InstanceParam name="NavServicesON" type="boolean" value="false"
--><!-- InstanceParam name="NavSupportON" type="boolean" value="false"
--><!-- InstanceParam name="NavNewsON" type="boolean"
value="false" --><!--
InstanceParam name="NavContactON" type="boolean" value="false" -->
<script language="JavaScript">
function breadCrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) { // by
Paul
Davis - http://www.kaosweaver.com
loc=window.location.toString();subs=loc.substr(loc.indexOf(base)+base.length+1).split("/");
document.write('<a href="'+getLoc(subs.length-1)+defp+'"
class="'+cStyle+'">Home</a> '+'<span class="'+dStyle+'">'+delStr+'</span>
');
a=(loc.indexOf(defp)==-1)?1:2;for (i=0;i<(subs.length-a);i++) {
subs=makeCaps(unescape(subs));
document.write('<a href="'+getLoc(subs.length-i-2)+defp+'"
class="'+cStyle+'">'+subs+'</a> '+'<span
class="'+dStyle+'">'+delStr+'</span> ');}
if (nl==1) document.write("<br>");document.write('<span
class="'+tStyle+'">'+document.title+'</span>');
}
function makeCaps(a) {
g=a.split(' ');for (l=0;l<g.length;l++)
g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
return g.join(" ");
}
function getLoc(c) {
var d="";if (c>0) for (k=0;k<c;k++) d=d+"../"; return d;
}
</script>
</head>

<body link="#6F96C6" alink="#6F96C6" vlink="#6F96C6">

<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="224"><a href="http://www.hksys.com"><img
src="images/hdr_logo.gif" alt="HKS Medical Information Systems"
width="187"
height="79" border="0"></a></td>
<td width="776"><!-- InstanceBeginEditable name="Header" --><img
src="images/hdr_home.jpg" alt="" height="79" style="width: 811px"><!--
InstanceEndEditable --></td>
</tr>
</table>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#6F96C6"> </td>
<td height="25" align="RIGHT" bgcolor="#6F96C6"><table width="990"
height="23" border="0" cellpadding="0" cellspacing="0">
<form action="search/search.pl" method="GET" name="SearchSite">
<input type="hidden" name="p" value="1" /><input type="hidden"
name="lang" value="en" /><input type="hidden" name="include" value=""
/><input type="hidden" name="exclude" value="" /><input type="hidden"
name="penalty" value="0" /><input type="HIDDEN" name="mode" value="any">

</form>
</table></td>
</tr>
<tr>
<td height="8" colspan="2"><img src="images/spacer.gif" width="1"
height="8"></td>
</tr>
</table>
<table width="996" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1000" valign="TOP"><table width="1000" border="0"
cellpadding="0" cellspacing="0" bgcolor="#A4A4A5">
<tr>
<td height="1" colspan="3"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>

<td width="1000" bgcolor="#FFFFFF"><table width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" bgcolor="#6F96C6"><!-- InstanceBeginEditable
name="PageTitle" --><span class="pageTitle">Support SLA
Compliance </span><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><table width="1000" border="0" cellpadding="0"
cellspacing="0">
<tr>

<td width="1000"><!-- InstanceBeginEditable
name="PageContent" -->
<form id="form1" runat="server">
<div>
<h1>
HKS Support Statistics</h1>
<p>
Click Links for more detail,
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/priority1-main.aspx">Priority 1 </asp:HyperLink>
Issues Last Updated:</span>
</p>
<p>
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="~/priority1-graph.aspx"
Target="_blank">Graph</asp:HyperLink> </p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_24hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority1 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority1 AS Priority1_1))

"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource1" Font-Names="Arial"
ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_24hrs" HeaderText="# of Issues
Resolved Within 24hrs"

SortExpression="Number_of_tickets_closed_within_24hrs" />
<asp:BoundField DataField="% of Tickets Closed within
SLAS" HeaderText="% of Issues Resolved Within SLAs"
SortExpression="% of Tickets Closed within SLAS" />
</Columns>
</asp:GridView>
</p>
<p>
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/priority2-main.aspx">Priority 2</asp:HyperLink> Issues Last
Updated:</span></p>
<p>
<span style="font-family: Arial"> <asp:HyperLink
ID="HyperLink5"
runat="server" NavigateUrl="~/priority2-graph.aspx"
Target="_blank">Graph</asp:HyperLink>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_48hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority2 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority2 AS Priority2_1))
"></asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333"
GridLines="None" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField
DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_48hrs" HeaderText="# of Issues
Resolved Within 48hrs"

SortExpression="Number_of_tickets_closed_within_48hrs" />
<asp:BoundField DataField="% of Tickets Closed
within SLAS" HeaderText="% of Issues Resolved Within SLAS"
SortExpression="% of Tickets Closed within
SLAS"
/>
</Columns>
</asp:GridView>
</span>
</p>
<p>
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink3" runat="server"
NavigateUrl="~/priority3-main.aspx">Priority 3</asp:HyperLink>
Issues Last Updated:</span></p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink6" runat="server"
NavigateUrl="~/priority3-graph.aspx"
Target="_blank">Graph</asp:HyperLink></span> </p>
<p>
<span style="font-family: Arial">
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
number_of_tickets_opened, number_of_tickets_closed_within_120hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority3 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority3 AS Priority3_1))"></asp:SqlDataSource>
<asp:GridView ID="GridView3" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource3" ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField
DataField="number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="number_of_tickets_opened" />
<asp:BoundField
DataField="number_of_tickets_closed_within_120hrs" HeaderText="# of Issues
Resolved Within 200hrs"

SortExpression="number_of_tickets_closed_within_120hrs" />
<asp:BoundField DataField="% of Tickets Closed
within SLAS" HeaderText="% of Issues Resolved Within SLAs"
SortExpression="% of Tickets Closed within
SLAS"
/>
</Columns>
</asp:GridView>
</span>
</p>

</div>
</form>
<!-- InstanceEndEditable --></td>

</tr>
</table></td>
</tr>
</table></td>
<td width="1"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>
<td height="1" colspan="3"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
</table></td>
</tr>
</table>
<table width="1000" border="0" cellpadding="8" cellspacing="0">
<tr>
<td width="1000" align="CENTER" class="footer">© 2006 HKS Medical
Information
Systems | <a href="http://web1.hksys.com/sw/" target="_blank"
class="footerLink">User
Support</a> | <a href="http://www.hksys.com/admin/" target="_blank"
class="footerLink">Client
Login</a> | <a href="default.htm" class="footerLink">Home</a></td>
</tr>
<tr>
<td bgcolor="#6F96C6"><img src="images/spacer.gif" width="1" height="10"
alt=""></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
 
many thanks for the quick reply. It is greatly appreciated

Excuse me for being naive but I am new to c# so am not sure how to create a
subclass.

Do you have any code snippets that I might be able to modify?

many thanks

Mike

Nicholas Paldino said:
Mike,

Have you considered creating a subclass of the data grid and exposing a
property which has the threshold for the value in column three? It might
make things a little easier for you.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mike Baugh said:
I am using visual studio 2005 to develop a form using c#

I have 3 datagrids on one form.

I can set the row color based on a certain value in a column. However this
color applies to all 3 datagrida. I would like to set it so that

if value of column 3 in datagrid 1 is < 100 set to red, if = 100 set to
green
if value of column 3 in datagrid 2 is < 90 set to red, if >= 90 set to
green
if value of column 3 in datagrid 3is < 80 set to red, if >= 80set to green

No matter how I write my code I cannot seem to get the coloring to apply
to
just one datagrid

My code is below:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<script runat="server">

protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{

}

protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 100)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}
}
protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (Decimal.Parse(e.Row.Cells[3].Text) < 70)
e.Row.Cells[3].BackColor = Color.IndianRed;
else
e.Row.Cells[3].BackColor = Color.MediumSeaGreen;
}

}


protected void Page_Load(object sender, EventArgs e)
{

}

protected void GridView2_SelectedIndexChanged(object sender, EventArgs
e)
{

}

</script>

<html><!-- InstanceBegin template="/Templates/supportstats.dwt"
codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>HKS Medical Information Systems</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" type="text/css" href="styles.css">
<script language="JavaScript" src="common.js"
type="text/JavaScript"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --><!--
InstanceParam name="NavAboutUsON" type="boolean" value="false" --><!--
InstanceParam name="NavSoftwareSolutionsON" type="boolean" value="false"
--><!-- InstanceParam name="NavServicesON" type="boolean" value="false"
--><!-- InstanceParam name="NavSupportON" type="boolean" value="false"
--><!-- InstanceParam name="NavNewsON" type="boolean"
value="false" --><!--
InstanceParam name="NavContactON" type="boolean" value="false" -->
<script language="JavaScript">
function breadCrumbs(base,delStr,defp,cStyle,tStyle,dStyle,nl) { // by
Paul
Davis - http://www.kaosweaver.com
loc=window.location.toString();subs=loc.substr(loc.indexOf(base)+base.length+1).split("/");
document.write('<a href="'+getLoc(subs.length-1)+defp+'"
class="'+cStyle+'">Home</a> '+'<span class="'+dStyle+'">'+delStr+'</span>
');
a=(loc.indexOf(defp)==-1)?1:2;for (i=0;i<(subs.length-a);i++) {
subs=makeCaps(unescape(subs));
document.write('<a href="'+getLoc(subs.length-i-2)+defp+'"
class="'+cStyle+'">'+subs+'</a> '+'<span
class="'+dStyle+'">'+delStr+'</span> ');}
if (nl==1) document.write("<br>");document.write('<span
class="'+tStyle+'">'+document.title+'</span>');
}
function makeCaps(a) {
g=a.split(' ');for (l=0;l<g.length;l++)
g[l]=g[l].toUpperCase().slice(0,1)+g[l].slice(1);
return g.join(" ");
}
function getLoc(c) {
var d="";if (c>0) for (k=0;k<c;k++) d=d+"../"; return d;
}
</script>
</head>

<body link="#6F96C6" alink="#6F96C6" vlink="#6F96C6">

<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="224"><a href="http://www.hksys.com"><img
src="images/hdr_logo.gif" alt="HKS Medical Information Systems"
width="187"
height="79" border="0"></a></td>
<td width="776"><!-- InstanceBeginEditable name="Header" --><img
src="images/hdr_home.jpg" alt="" height="79" style="width: 811px"><!--
InstanceEndEditable --></td>
</tr>
</table>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="25" bgcolor="#6F96C6"> </td>
<td height="25" align="RIGHT" bgcolor="#6F96C6"><table width="990"
height="23" border="0" cellpadding="0" cellspacing="0">
<form action="search/search.pl" method="GET" name="SearchSite">
<input type="hidden" name="p" value="1" /><input type="hidden"
name="lang" value="en" /><input type="hidden" name="include" value=""
/><input type="hidden" name="exclude" value="" /><input type="hidden"
name="penalty" value="0" /><input type="HIDDEN" name="mode" value="any">

</form>
</table></td>
</tr>
<tr>
<td height="8" colspan="2"><img src="images/spacer.gif" width="1"
height="8"></td>
</tr>
</table>
<table width="996" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1000" valign="TOP"><table width="1000" border="0"
cellpadding="0" cellspacing="0" bgcolor="#A4A4A5">
<tr>
<td height="1" colspan="3"><img src="images/spacer.gif" width="1"
height="1"></td>
</tr>
<tr>

<td width="1000" bgcolor="#FFFFFF"><table width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td width="100%" bgcolor="#6F96C6"><!-- InstanceBeginEditable
name="PageTitle" --><span class="pageTitle">Support SLA
Compliance </span><!-- InstanceEndEditable --></td>
</tr>
<tr>
<td><table width="1000" border="0" cellpadding="0"
cellspacing="0">
<tr>

<td width="1000"><!-- InstanceBeginEditable
name="PageContent" -->
<form id="form1" runat="server">
<div>
<h1>
HKS Support Statistics</h1>
<p>
Click Links for more detail,
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl="~/priority1-main.aspx">Priority 1 </asp:HyperLink>
Issues Last Updated:</span>
</p>
<p>
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="~/priority1-graph.aspx"
Target="_blank">Graph</asp:HyperLink> </p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_24hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority1 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority1 AS Priority1_1))

"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource1" Font-Names="Arial"
ForeColor="#333333" GridLines="None"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged" >
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_24hrs" HeaderText="# of Issues
Resolved Within 24hrs"

SortExpression="Number_of_tickets_closed_within_24hrs" />
<asp:BoundField DataField="% of Tickets Closed within
SLAS" HeaderText="% of Issues Resolved Within SLAs"
SortExpression="% of Tickets Closed within SLAS" />
</Columns>
</asp:GridView>
</p>
<p>
</p>
<p>
<span style="font-family: Arial">
<asp:HyperLink ID="HyperLink2" runat="server"
NavigateUrl="~/priority2-main.aspx">Priority 2</asp:HyperLink> Issues Last
Updated:</span></p>
<p>
<span style="font-family: Arial"> <asp:HyperLink
ID="HyperLink5"
runat="server" NavigateUrl="~/priority2-graph.aspx"
Target="_blank">Graph</asp:HyperLink>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:SupportStatsConnectionString %>"
SelectCommand="SELECT Priority, Date,
Number_of_tickets_opened, Number_of_tickets_closed_within_48hrs,
ROUND([%_of_tickets_closed_within_slas], 0) AS '% of Tickets Closed within
SLAS' FROM dbo.Priority2 WHERE (Date IN (SELECT MAX(Date) AS date FROM
dbo.Priority2 AS Priority2_1))
"></asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server"
OnRowDataBound="GridView1_RowDataBound" AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource2" ForeColor="#333333"
GridLines="None" OnSelectedIndexChanged="GridView2_SelectedIndexChanged">
<FooterStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#E3EAEB" HorizontalAlign="Center"
Font-Bold="True" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True"
ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="Date"
ReadOnly="True" SortExpression="Date" />
<asp:BoundField
DataField="Number_of_tickets_opened"
HeaderText="# of Issues Opened"
SortExpression="Number_of_tickets_opened" />
<asp:BoundField
DataField="Number_of_tickets_closed_within_48hrs" HeaderText="# of Issues
Resolved Within 48hrs"

SortExpression="Number_of_tickets_closed_within_48hrs" />
<asp:BoundField DataField="% of Tickets Closed
within SLAS" HeaderText="% of Issues Resolved Within SLAS"
 
Back
Top