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

C

Chico

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
 
K

Kyle Peterson

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
 
C

Chico

Thanks for responding. We're talking InterDev 6.0


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 said:
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
 
K

Kyle Peterson

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 said:
Thanks for responding. We're talking InterDev 6.0


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 said:
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
 
A

Adrienne

Gazing into my crystal ball I observed "Kyle Peterson"
<[email protected]> writing in

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>
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 said:
Thanks for responding. We're talking InterDev 6.0


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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top