BGCOLOR of the row in dataGrid

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

I have dataGrid.
I would like that item background(row of the dataGrid) is red if the active
field in database is false
otherwise leave it like it is.

I tried like this:

<asp:DataGrid ItemStyle-BackColor='<%#
checkActive(DataBinder.Eval(Container.DataItem, "active"))%>'>

and in code behind:

Public Function checkActive(ByVal vrednost As Boolean) As Color
If vrednost = False Then
PreveriAktivnost = System.Drawing.Color.Red
End If
End Function

I get an error message:
'DataItem' is not a member of 'System.Web.UI.Control'.

How can I solve this problem? Maybe onItemCreated and check there?

Thank you,
Simon
 
Maybe the syntax is wrong? The syntax I use for framework 1.1 is.......
DataBinder.Eval(Container, "DataItem.ShortDesc")
 
no, the sintaks is ok.
I think I can't put the container in dataGrid tag.
I should use onItemcomand or something similar

thank you,
Simon
 
You can use ItemDataBound event like this:

private void yourDataGrid_ItemDataBound (object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) ||
(e.Item.ItemType == ListItemType.AlternatingItem))
if (e.Item.Cells["active"].Text == "Y")
e.Item.BackColor = System.Drawing.Color.Red;
}

Eliyahu
 
Back
Top