data grid conditional row formatting

Discussion in 'ASP .Net' started by Brian Henry, Jul 8, 2004.

  1. Brian Henry

    Brian Henry Guest

    How would i format a web data grid conditionally?

    If column 1 is the value true i want the row to be white, else if it is
    false i want the row to be blue, thanks
     
    Brian Henry, Jul 8, 2004
    #1
    1. Advertising

  2. use ItemDataBound event of datagrid control
    and

    private void DataGrid1_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    ListItemType.AlternatingItem )
    {
    string color = "";
    if ( bool.Parse(e.Item.Cells[0].Text) )
    color = "#FF0000";
    else
    color = "#00FFFF";

    for ( int i=0; i < e.Item.Cells.Count; i ++ )
    {
    e.Item.Cells.BackColor = Color.FromName(color);
    }
    }
    }

    where in the first column i have the true/false value as a text

    Regards
    Martin


    "Brian Henry" <> wrote in message
    news:#Hi$...
    > How would i format a web data grid conditionally?
    >
    > If column 1 is the value true i want the row to be white, else if it is
    > false i want the row to be blue, thanks
    >
    >
     
    Martin Marinov, Jul 8, 2004
    #2
    1. Advertising

  3. Brian Henry

    Brian Henry Guest

    thanks

    "Martin Marinov" <> wrote in message
    news:%23L%...
    >
    > use ItemDataBound event of datagrid control
    > and
    >
    > private void DataGrid1_ItemDataBound(object sender,
    > System.Web.UI.WebControls.DataGridItemEventArgs e)
    > {
    > if ( e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
    > ListItemType.AlternatingItem )
    > {
    > string color = "";
    > if ( bool.Parse(e.Item.Cells[0].Text) )
    > color = "#FF0000";
    > else
    > color = "#00FFFF";
    >
    > for ( int i=0; i < e.Item.Cells.Count; i ++ )
    > {
    > e.Item.Cells.BackColor = Color.FromName(color);
    > }
    > }
    > }
    >
    > where in the first column i have the true/false value as a text
    >
    > Regards
    > Martin
    >
    >
    > "Brian Henry" <> wrote in message
    > news:#Hi$...
    > > How would i format a web data grid conditionally?
    > >
    > > If column 1 is the value true i want the row to be white, else if it is
    > > false i want the row to be blue, thanks
    > >
    > >

    >
    >
     
    Brian Henry, Jul 8, 2004
    #3
    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. Andrew Kidd

    Formatting a row in a grid

    Andrew Kidd, Aug 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    383
    Andrew Kidd
    Aug 30, 2003
  2. DC

    Conditional Row in Grid

    DC, Dec 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    453
    Konrad Rotuski
    Dec 23, 2003
  3. Bazza Formez
    Replies:
    4
    Views:
    417
    Vanni Tomezzoli
    Dec 9, 2004
  4. Keith G Hicks
    Replies:
    5
    Views:
    403
    Keith G Hicks
    Apr 8, 2008
  5. D
    Replies:
    0
    Views:
    240
Loading...

Share This Page