BGCOLOR of the row in dataGrid

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
 
C

Craig

Maybe the syntax is wrong? The syntax I use for framework 1.1 is.......
DataBinder.Eval(Container, "DataItem.ShortDesc")
 
S

simon

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
 
E

Eliyahu Goldin

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
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top