469,352 Members | 2,140 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

How do you dynamically set the color in an ASP DataGrid?

Hi,

I have an ASP page that was built using MS Visual InterDev. The
original programmer used the MS Visual InterDev DataGrid control to
render his recordset. What I need to do is to change one of the cell
colors based on a database value. Right now the code looks like this:

function _Grid1_ctor()
{
CreateDataGrid('Grid1',_initGrid1);
}

function _initGrid1()
{
if (Session("HaveFoodGroup") == true)
{
Grid1.colHeader[1] = '"Food Group"';
Grid1.colAttributes[1] = set_cell_color();
Grid1.colData[1] = 'get_foodgroup()';
}
}

function set_cell_color()
{
var stemp = Recordset1.fields.getValue("foodGroup");
var cellColor;
if (stemp == "Meats")
cellColor = ' bgcolor="Red"';
if (stemp == "Dairy")
cellColor = 'bgcolor="White";
return stemp;
}

function get_foodgroup()
{
var stemp = Recordset1.fields.getValue("foodGroup");
return stemp;
}

}

My problem is that when the page is rendered the background color of
all the cells is red. This is because the last record in my recordset
is a Meat foodgroup. However, Grid.colData[1] is properly displaying
the foodgroups.

Can someone tell me what's going on?

Thanks

Jul 22 '05 #1
4 1306
how far back we talking about
was it visual interdev 1 ? or 6 ?

the controls in version 1 were pretty worthless from what I remember
"Chico" <ck*@ameritech.net> wrote in message
news:6l********************************@4ax.com...
Hi,

I have an ASP page that was built using MS Visual InterDev. The
original programmer used the MS Visual InterDev DataGrid control to
render his recordset. What I need to do is to change one of the cell
colors based on a database value. Right now the code looks like this:

function _Grid1_ctor()
{
CreateDataGrid('Grid1',_initGrid1);
}

function _initGrid1()
{
if (Session("HaveFoodGroup") == true)
{
Grid1.colHeader[1] = '"Food Group"';
Grid1.colAttributes[1] = set_cell_color();
Grid1.colData[1] = 'get_foodgroup()';
}
}

function set_cell_color()
{
var stemp = Recordset1.fields.getValue("foodGroup");
var cellColor;
if (stemp == "Meats")
cellColor = ' bgcolor="Red"';
if (stemp == "Dairy")
cellColor = 'bgcolor="White";
return stemp;
}

function get_foodgroup()
{
var stemp = Recordset1.fields.getValue("foodGroup");
return stemp;
}

}

My problem is that when the page is rendered the background color of
all the cells is red. This is because the last record in my recordset
is a Meat foodgroup. However, Grid.colData[1] is properly displaying
the foodgroups.

Can someone tell me what's going on?

Thanks

Jul 22 '05 #2
Thanks for responding. We're talking InterDev 6.0
On Mon, 2 May 2005 13:50:09 -0400, "Kyle Peterson"
<kp*****@hotmail.com> wrote:
how far back we talking about
was it visual interdev 1 ? or 6 ?

the controls in version 1 were pretty worthless from what I remember
"Chico" <ck*@ameritech.net> wrote in message
news:6l********************************@4ax.com.. .
Hi,

I have an ASP page that was built using MS Visual InterDev. The
original programmer used the MS Visual InterDev DataGrid control to
render his recordset. What I need to do is to change one of the cell
colors based on a database value. Right now the code looks like this:

function _Grid1_ctor()
{
CreateDataGrid('Grid1',_initGrid1);
}

function _initGrid1()
{
if (Session("HaveFoodGroup") == true)
{
Grid1.colHeader[1] = '"Food Group"';
Grid1.colAttributes[1] = set_cell_color();
Grid1.colData[1] = 'get_foodgroup()';
}
}

function set_cell_color()
{
var stemp = Recordset1.fields.getValue("foodGroup");
var cellColor;
if (stemp == "Meats")
cellColor = ' bgcolor="Red"';
if (stemp == "Dairy")
cellColor = 'bgcolor="White";
return stemp;
}

function get_foodgroup()
{
var stemp = Recordset1.fields.getValue("foodGroup");
return stemp;
}

}

My problem is that when the page is rendered the background color of
all the cells is red. This is because the last record in my recordset
is a Meat foodgroup. However, Grid.colData[1] is properly displaying
the foodgroups.

Can someone tell me what's going on?

Thanks


Jul 22 '05 #3
humm, still hard to say

I dont think too many people use interdev 6 anymore.. I havent used it in
like 3 years or so and it was also pretty useless at the time... basically
they tried to make everything all object oriented before it was ready to be
object oriented.. and then half the stuff didnt work right

sorry

unless someone here has a good answer for you you might want to just rewrite
the code real quick so it doesn't use that old datagrid code.

"Chico" <ck*@ameritech.net> wrote in message
news:is********************************@4ax.com...
Thanks for responding. We're talking InterDev 6.0
On Mon, 2 May 2005 13:50:09 -0400, "Kyle Peterson"
<kp*****@hotmail.com> wrote:
how far back we talking about
was it visual interdev 1 ? or 6 ?

the controls in version 1 were pretty worthless from what I remember
"Chico" <ck*@ameritech.net> wrote in message
news:6l********************************@4ax.com. ..
Hi,

I have an ASP page that was built using MS Visual InterDev. The
original programmer used the MS Visual InterDev DataGrid control to
render his recordset. What I need to do is to change one of the cell
colors based on a database value. Right now the code looks like this:

function _Grid1_ctor()
{
CreateDataGrid('Grid1',_initGrid1);
}

function _initGrid1()
{
if (Session("HaveFoodGroup") == true)
{
Grid1.colHeader[1] = '"Food Group"';
Grid1.colAttributes[1] = set_cell_color();
Grid1.colData[1] = 'get_foodgroup()';
}
}

function set_cell_color()
{
var stemp = Recordset1.fields.getValue("foodGroup");
var cellColor;
if (stemp == "Meats")
cellColor = ' bgcolor="Red"';
if (stemp == "Dairy")
cellColor = 'bgcolor="White";
return stemp;
}

function get_foodgroup()
{
var stemp = Recordset1.fields.getValue("foodGroup");
return stemp;
}

}

My problem is that when the page is rendered the background color of
all the cells is red. This is because the last record in my recordset
is a Meat foodgroup. However, Grid.colData[1] is properly displaying
the foodgroups.

Can someone tell me what's going on?

Thanks

Jul 22 '05 #4
Gazing into my crystal ball I observed "Kyle Peterson"
<kp*****@hotmail.com> writing in
news:Ov**************@TK2MSFTNGP15.phx.gbl:

You could use classes, eg:

<style type="text/css">
..meat {background-color: red; color: white}
..fruit {background-color: pink; color: black}
..vegetable {background-color: green; color: white}
..other {background-color:white; color:black}
</style>

<tr class="<%=foodgroup%>">
<td><%=item%></td>
</tr>
<tr class="<%=foodgroup%>">
humm, still hard to say

I dont think too many people use interdev 6 anymore.. I havent used it
in like 3 years or so and it was also pretty useless at the time...
basically they tried to make everything all object oriented before it
was ready to be object oriented.. and then half the stuff didnt work
right

sorry

unless someone here has a good answer for you you might want to just
rewrite the code real quick so it doesn't use that old datagrid code.

"Chico" <ck*@ameritech.net> wrote in message
news:is********************************@4ax.com...
Thanks for responding. We're talking InterDev 6.0
On Mon, 2 May 2005 13:50:09 -0400, "Kyle Peterson"
<kp*****@hotmail.com> wrote:
how far back we talking about
was it visual interdev 1 ? or 6 ?

the controls in version 1 were pretty worthless from what I remember
"Chico" <ck*@ameritech.net> wrote in message
news:6l********************************@4ax.com ...
Hi,

I have an ASP page that was built using MS Visual InterDev. The
original programmer used the MS Visual InterDev DataGrid control to
render his recordset. What I need to do is to change one of the
cell colors based on a database value. Right now the code looks
like this:

function _Grid1_ctor()
{
CreateDataGrid('Grid1',_initGrid1); }

function _initGrid1()
{
if (Session("HaveFoodGroup") == true)
{
Grid1.colHeader[1] = '"Food Group"';
Grid1.colAttributes[1] = set_cell_color();
Grid1.colData[1] = 'get_foodgroup()'; } }

function set_cell_color()
{
var stemp = Recordset1.fields.getValue("foodGroup");
var cellColor;
if (stemp == "Meats")
cellColor = ' bgcolor="Red"';
if (stemp == "Dairy")
cellColor = 'bgcolor="White";
return stemp;
}

function get_foodgroup()
{
var stemp = Recordset1.fields.getValue("foodGroup");
return stemp;
}

}

My problem is that when the page is rendered the background color of
all the cells is red. This is because the last record in my
recordset is a Meat foodgroup. However, Grid.colData[1] is properly
displaying the foodgroups.

Can someone tell me what's going on?

Thanks



--
Adrienne Boswell
http://www.cavalcade-of-coding.info
Please respond to the group so others can share
Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by sameer mowade via .NET 247 | last post: by
6 posts views Thread by John Ruiz | last post: by
4 posts views Thread by bill | last post: by
4 posts views Thread by Shiju Poyilil | last post: by
3 posts views Thread by david | last post: by
4 posts views Thread by sydney.luu | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.