BGCOLOR of the row in dataGrid

Discussion in 'ASP .Net' started by simon, May 11, 2004.

  1. simon

    simon Guest

    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
    simon, May 11, 2004
    #1
    1. Advertising

  2. simon

    Craig Guest

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

    "simon" <> wrote in message
    news:...
    > 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
    >
    >
    Craig, May 11, 2004
    #2
    1. Advertising

  3. simon

    simon Guest

    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

    "Craig" <> wrote in message
    news:%...
    > Maybe the syntax is wrong? The syntax I use for framework 1.1 is.......
    > DataBinder.Eval(Container, "DataItem.ShortDesc")
    >
    > "simon" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    simon, May 11, 2004
    #3
  4. 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

    "simon" <> wrote in message
    news:...
    > 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
    >
    >
    Eliyahu Goldin, May 11, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SkM=?=

    Changing DataGrid Item BGCOLOR

    =?Utf-8?B?SkM=?=, Mar 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    349
    =?Utf-8?B?SkM=?=
    Mar 6, 2004
  2. Charles Shao
    Replies:
    1
    Views:
    389
    Eliyahu Goldin
    Apr 18, 2005
  3. simon

    bgcolor of repeater row

    simon, May 31, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,521
    Eliyahu Goldin
    May 31, 2005
  4. TC
    Replies:
    0
    Views:
    95
  5. Martin
    Replies:
    2
    Views:
    99
    Rob B
    Nov 19, 2004
Loading...

Share This Page