datagrid

T

Trond

I have a form with a datagrid that is databound. One of the column is like
this:

<asp:BoundColumn DataField="Timediff"
SortExpression="Timediff"
HeaderText="Time difference">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:BoundColumn>

In that column i display a number from 0 to 3 mill

Is there a way i can replace that with graphics?
If number is < 60 then green
if number is = 60 then yellow
if number is > 60 then red

best regards
Trond
 
G

Guest

Best bet would be to set this up as a template column and put a control in
there that you can colour. Then in the item_create event for the grid, you
could check the value for this specific row/col and set the colour of the
control accordingly

Dave
 
G

Guest

Hi Trond,

You can process in DataGrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
TableCell cell = e.Item.Cells[TimediffIndex];
double Timediff = double.Parse(cell.Text);
if (Timediff == 60)
{
cell.BackColor = Color.Yellow;
}
else
{
if (Timediff < 60)
{
cell.BackColor = Color.Green;
}
else
{
cell.BackColor = Color.Red;
}
}
}


HTH

Elton Wang
(e-mail address removed)
 
T

Trond

Thank you so much. What is TimediffIndex? The code reports an error with
that saying: The name 'TimediffIndex' does not exist in the class or
namespace

best regards
Trond


Elton W said:
Hi Trond,

You can process in DataGrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
TableCell cell = e.Item.Cells[TimediffIndex];
double Timediff = double.Parse(cell.Text);
if (Timediff == 60)
{
cell.BackColor = Color.Yellow;
}
else
{
if (Timediff < 60)
{
cell.BackColor = Color.Green;
}
else
{
cell.BackColor = Color.Red;
}
}
}


HTH

Elton Wang
(e-mail address removed)



Trond said:
I have a form with a datagrid that is databound. One of the column is
like
this:

<asp:BoundColumn DataField="Timediff"
SortExpression="Timediff"
HeaderText="Time difference">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:BoundColumn>

In that column i display a number from 0 to 3 mill

Is there a way i can replace that with graphics?
If number is < 60 then green
if number is = 60 then yellow
if number is > 60 then red

best regards
Trond
 
G

Guest

TimediffIndex means the index of your Timediff column, e.g. 0 for the first
column.

HTH

Elton Wang

Trond said:
Thank you so much. What is TimediffIndex? The code reports an error with
that saying: The name 'TimediffIndex' does not exist in the class or
namespace

best regards
Trond


Elton W said:
Hi Trond,

You can process in DataGrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
TableCell cell = e.Item.Cells[TimediffIndex];
double Timediff = double.Parse(cell.Text);
if (Timediff == 60)
{
cell.BackColor = Color.Yellow;
}
else
{
if (Timediff < 60)
{
cell.BackColor = Color.Green;
}
else
{
cell.BackColor = Color.Red;
}
}
}


HTH

Elton Wang
(e-mail address removed)



Trond said:
I have a form with a datagrid that is databound. One of the column is
like
this:

<asp:BoundColumn DataField="Timediff"
SortExpression="Timediff"
HeaderText="Time difference">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:BoundColumn>

In that column i display a number from 0 to 3 mill

Is there a way i can replace that with graphics?
If number is < 60 then green
if number is = 60 then yellow
if number is > 60 then red

best regards
Trond
 
T

Trond

Yes I see. Thank you. I changed it to the column number and presto,
everything is working fine.
As a newbie I really appreciate that you took time to write code
Best regards
Trond

Elton W said:
TimediffIndex means the index of your Timediff column, e.g. 0 for the
first
column.

HTH

Elton Wang

Trond said:
Thank you so much. What is TimediffIndex? The code reports an error with
that saying: The name 'TimediffIndex' does not exist in the class or
namespace

best regards
Trond


Elton W said:
Hi Trond,

You can process in DataGrid_ItemDataBound event:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
TableCell cell = e.Item.Cells[TimediffIndex];
double Timediff = double.Parse(cell.Text);
if (Timediff == 60)
{
cell.BackColor = Color.Yellow;
}
else
{
if (Timediff < 60)
{
cell.BackColor = Color.Green;
}
else
{
cell.BackColor = Color.Red;
}
}
}


HTH

Elton Wang
(e-mail address removed)



:

I have a form with a datagrid that is databound. One of the column is
like
this:

<asp:BoundColumn DataField="Timediff"
SortExpression="Timediff"
HeaderText="Time difference">
<HeaderStyle Wrap="False"></HeaderStyle>
</asp:BoundColumn>

In that column i display a number from 0 to 3 mill

Is there a way i can replace that with graphics?
If number is < 60 then green
if number is = 60 then yellow
if number is > 60 then red

best regards
Trond
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top