Condition Formatting on GridView

Discussion in 'ASP .Net' started by Jim in Arizona, Aug 16, 2006.

  1. Using a GridView or other data reading control (gridview, datagrid,
    datalist), how can I do conditional formatting on the results pulled
    from an access database? As an exampe, use a sql statement to bind to
    the datagrid, and one of the columns has numerical data. How would I,
    say, make any data in that column that is over 1000 to be in red or bold?

    If this can't be done using one of these controls, how else would I get
    the job done?

    Sometimes I feel I'm over my head, but, it's good to know these groups
    exist.

    TIA,
    Jim
     
    Jim in Arizona, Aug 16, 2006
    #1
    1. Advertising

  2. Jim in Arizona

    David Wier Guest

    Check out this code sample at ASPNet101.com:
    http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=gvcellcolor

    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://aspexpress.com

    "Jim in Arizona" <> wrote in message
    news:%23Kv$...
    > Using a GridView or other data reading control (gridview, datagrid,
    > datalist), how can I do conditional formatting on the results pulled from
    > an access database? As an exampe, use a sql statement to bind to the
    > datagrid, and one of the columns has numerical data. How would I, say,
    > make any data in that column that is over 1000 to be in red or bold?
    >
    > If this can't be done using one of these controls, how else would I get
    > the job done?
    >
    > Sometimes I feel I'm over my head, but, it's good to know these groups
    > exist.
    >
    > TIA,
    > Jim
     
    David Wier, Aug 17, 2006
    #2
    1. Advertising

  3. David Wier wrote:
    > Check out this code sample at ASPNet101.com:
    > http://aspnet101.com/aspnet101/aspnet/codesample.aspx?code=gvcellcolor
    >
    > David Wier
    > MVP/ASPInsider
    > http://aspnet101.com
    > http://aspexpress.com
    >


    The example you pointed me to worked like a charm. Thanks for your help!

    Here's my code in case anyone is curious.

    In the aspx file:

    <asp:GridView ID="gvData" runat="server" OnRowDataBound="doColor">

    In the aspx.vb file (the btnSubmit sub is cut down for space):

    Sub doColor(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
    If e.Row.Cells(10).Text > "44" Then
    e.Row.BackColor = Drawing.Color.LightYellow
    e.Row.Cells(10).ForeColor = Drawing.Color.Red
    e.Row.Cells(10).Font.Bold = True
    End If
    If e.Row.Cells(11).Text > "59" Then
    e.Row.BackColor = Drawing.Color.LightYellow
    e.Row.Cells(11).ForeColor = Drawing.Color.Red
    e.Row.Cells(11).Font.Bold = True
    End If
    End If
    End Sub

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles btnSubmit.Click

    objConnection.Open()
    gvData.DataSource =
    objCommand.ExecuteReader(CommandBehavior.CloseConnection)
    gvData.DataBind()
    If objConnection.State = ConnectionState.Open Then
    objConnection.Close()
    End If

    End Sub
     
    Jim in Arizona, Aug 17, 2006
    #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. -
    Replies:
    12
    Views:
    707
    Remon van Vliet
    Jun 15, 2005
  2. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,022
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  3. Mike P
    Replies:
    3
    Views:
    4,273
    PeterKellner
    Jun 6, 2006
  4. =?Utf-8?B?TWFya0F1cml0?=

    GRIDVIEW: condition processing

    =?Utf-8?B?TWFya0F1cml0?=, Feb 7, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    372
    Eliyahu Goldin
    Feb 7, 2007
  5. Bill W.
    Replies:
    13
    Views:
    308
    Phillip Gawlowski
    May 9, 2011
Loading...

Share This Page