Formatting a row in a grid

Discussion in 'ASP .Net' started by Andrew Kidd, Aug 30, 2003.

  1. Andrew Kidd

    Andrew Kidd Guest

    Hi,

    I've decided to bite the bullet and try my hand at this .Net stuff & doing OK so far, but I can't seem to work this last problem out.

    I need to change the font colour of a row depending on a value in the underlying recordset. In 'classic asp' I do something like this:

    ..
    ..
    ..
    If rs_main.Fields("Flag") = True Then
    strFontColour = "#FF0000"
    Else
    strFontColour = "#000000"
    End If %>
    ..
    ..
    ..
    <td width="15%"><font color="<%=strFontColour%>"><%=rs_main.fields("MemberName")%></font></td>

    In ASP.Net I've got something like this:

    Private Sub grdMembers_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdMembers.ItemCreated
    If e.Item.ItemType = ListItemType.Item And e.Item.Cells(2).Text = "True" Then
    e.Item.ForeColor = System.Drawing.Color.Red
    End If
    End Sub

    ....But it's not working. Also, in the 'classic asp' approach I don't output the field into the table, just have it in the query so that I can test for it. Now, if it's in the DataReader it's going to show up & I don't want it to.

    Where have I gone wrong in the code & how do I not show a field in the grid for the value that I'm testing for?

    Thanks in advance,

    Andy
     
    Andrew Kidd, Aug 30, 2003
    #1
    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. Brian Henry

    data grid conditional row formatting

    Brian Henry, Jul 8, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,088
    Brian Henry
    Jul 8, 2004
  2. =?Utf-8?B?TGVlIEhvbHNlbmJlY2s=?=

    Re: how do i keep .net from re-formatting controls on grid layout

    =?Utf-8?B?TGVlIEhvbHNlbmJlY2s=?=, Jul 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    295
    Jeremy
    Jul 20, 2004
  3. Bazza Formez
    Replies:
    4
    Views:
    405
    Vanni Tomezzoli
    Dec 9, 2004
  4. IK

    How to find grid's row that matches row in dataset

    IK, Sep 15, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    178
  5. D
    Replies:
    0
    Views:
    220
Loading...

Share This Page