DataGrid + CSS

  • Thread starter Thread starter Alexander Widera
  • Start date Start date
A

Alexander Widera

Hi,
at first a little bit of the code ...

<ASP:DataGrid id="an" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="status" HeaderText="status" />
</Columns>
</ASP:DataGrid>

Some rows of this DataGrid, which is filled with an database, should get a
different color... perhaps with a css-class. How can I make this?

I tried this:
<asp:BoundColumn DataField="status" HeaderText="status"
ItemStyle-BackColor=<%# DataBinder.Eval(Container.DataItem, "Colour") %> />

But this doesn't work ... :-(

Please help me...
Thank you


Bye Alex
 
Hi Alexander,

Following code snippet in datagrid_ItemDataBound event
shows how to change color in a datagrid:


if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType = ListItemType.Item )
{

if (e.Item.Cells[statusIndex].Text.Equals
(something))
{
e.Item.BackColor = Color.SomeColor;
// whole row
// or
e.Item.Cells[statusIndex].BackColor =
Color.SomeColor; // single cell
}
}

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----
Hi,
at first a little bit of the code ...

<ASP:DataGrid id="an" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="status" HeaderText="status" />
</Columns>
</ASP:DataGrid>

Some rows of this DataGrid, which is filled with an database, should get a
different color... perhaps with a css-class. How can I make this?

I tried this:
<asp:BoundColumn DataField="status" HeaderText="status"
ItemStyle-BackColor=<%# DataBinder.Eval
(Container.DataItem, "Colour") %> />
 
thank you very much....
now i got it..


Elton Wang said:
Hi Alexander,

Following code snippet in datagrid_ItemDataBound event
shows how to change color in a datagrid:


if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType = ListItemType.Item )
{

if (e.Item.Cells[statusIndex].Text.Equals
(something))
{
e.Item.BackColor = Color.SomeColor;
// whole row
// or
e.Item.Cells[statusIndex].BackColor =
Color.SomeColor; // single cell
}
}

HTH

Elton Wang
(e-mail address removed)

-----Original Message-----
Hi,
at first a little bit of the code ...

<ASP:DataGrid id="an" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundColumn DataField="status" HeaderText="status" />
</Columns>
</ASP:DataGrid>

Some rows of this DataGrid, which is filled with an database, should get a
different color... perhaps with a css-class. How can I make this?

I tried this:
<asp:BoundColumn DataField="status" HeaderText="status"
ItemStyle-BackColor=<%# DataBinder.Eval
(Container.DataItem, "Colour") %> />
But this doesn't work ... :-(

Please help me...
Thank you


Bye Alex


.
 

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

Back
Top