Set a bgcolor in a repeater based on databse value asp newbie

Discussion in 'ASP .Net' started by Jim Florence, Jun 23, 2006.

  1. Jim Florence

    Jim Florence Guest

    Hi,

    I'm just starting to write in asp and have been trying to create a repeater
    to display some data in a simple form.

    The basics worked ok and then I tried to set a bgcolor on a cell based on
    it's value, I have read and re-read a good few things but nothing seems to
    point to this scenario directly. I know the following code doesn't actually
    work but this is roughly what I'm trying to do. eventually I want to do the
    same thing with dates but baby steps first :)

    <ItemTemplate>
    <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
    "something") Then%>'
    <tr>
    <td bgcolor="#ff0000">
    <%Else%>
    <tr>
    <td bgcolor="#CCFFCC">
    <% End If%>
    <asp:Label runat="server" ID="Labell" Text='<%#
    Eval("CategoryName") %>' />
    </td>
    <td bgcolor="#CCFFCC">
    <asp:Label runat="server" ID="Label2" Text='<%#
    Eval("Description") %>' />
    </td>
    </tr>
    </ItemTemplate>

    Thanks in advance for any help

    Jim Florence
    Jim Florence, Jun 23, 2006
    #1
    1. Advertising

  2. Instead of attempting to change the colour of the <ItemTemplate>, add an
    <AlternatingItemTemplate> section and type the colour in there. dotNet will
    then take care of the rest for you.



    "Jim Florence" wrote:

    >
    > Hi,
    >
    > I'm just starting to write in asp and have been trying to create a repeater
    > to display some data in a simple form.
    >
    > The basics worked ok and then I tried to set a bgcolor on a cell based on
    > it's value, I have read and re-read a good few things but nothing seems to
    > point to this scenario directly. I know the following code doesn't actually
    > work but this is roughly what I'm trying to do. eventually I want to do the
    > same thing with dates but baby steps first :)
    >
    > <ItemTemplate>
    > <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
    > "something") Then%>'
    > <tr>
    > <td bgcolor="#ff0000">
    > <%Else%>
    > <tr>
    > <td bgcolor="#CCFFCC">
    > <% End If%>
    > <asp:Label runat="server" ID="Labell" Text='<%#
    > Eval("CategoryName") %>' />
    > </td>
    > <td bgcolor="#CCFFCC">
    > <asp:Label runat="server" ID="Label2" Text='<%#
    > Eval("Description") %>' />
    > </td>
    > </tr>
    > </ItemTemplate>
    >
    > Thanks in advance for any help
    >
    > Jim Florence
    >
    =?Utf-8?B?RGVhbg==?=, Jun 23, 2006
    #2
    1. Advertising

  3. Jim Florence

    Jim Florence Guest

    "Dean" <> wrote in message
    news:...
    Dean,

    Thanks for the reply, that works great for the entire row but not for
    individual cells within the row based on the cell's value or name.

    What I'm eventually trying to do is set an individual date cell to be either
    red, amber or green depending on how many days overdue an item is

    Many thanks again

    Jim


    >Instead of attempting to change the colour of the <ItemTemplate>, add an
    > <AlternatingItemTemplate> section and type the colour in there. dotNet
    > will
    > then take care of the rest for you.
    >
    >
    >
    > "Jim Florence" wrote:
    >
    >>
    >> Hi,
    >>
    >> I'm just starting to write in asp and have been trying to create a
    >> repeater
    >> to display some data in a simple form.
    >>
    >> The basics worked ok and then I tried to set a bgcolor on a cell based on
    >> it's value, I have read and re-read a good few things but nothing seems
    >> to
    >> point to this scenario directly. I know the following code doesn't
    >> actually
    >> work but this is roughly what I'm trying to do. eventually I want to do
    >> the
    >> same thing with dates but baby steps first :)
    >>
    >> <ItemTemplate>
    >> <%If #(DataBinder.Eval(Container.DataItem, "CategoryName") =
    >> "something") Then%>'
    >> <tr>
    >> <td bgcolor="#ff0000">
    >> <%Else%>
    >> <tr>
    >> <td bgcolor="#CCFFCC">
    >> <% End If%>
    >> <asp:Label runat="server" ID="Labell" Text='<%#
    >> Eval("CategoryName") %>' />
    >> </td>
    >> <td bgcolor="#CCFFCC">
    >> <asp:Label runat="server" ID="Label2" Text='<%#
    >> Eval("Description") %>' />
    >> </td>
    >> </tr>
    >> </ItemTemplate>
    >>
    >> Thanks in advance for any help
    >>
    >> Jim Florence
    >>
    Jim Florence, Jun 23, 2006
    #3
  4. Jim Florence

    chris Guest

    Jim,

    Try this instead:
    <td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
    "something"?"#ff0000":"#ffffff"%>'>

    This assumes that you are in C#, in VB i think there is a immediate if
    of IIf();

    HTH,
    Chris
    chris, Jun 24, 2006
    #4
  5. Jim Florence

    Jim Florence Guest

    "chris" <> wrote in message
    news:...
    Chris your a star,

    After very minor fiddling the code is

    <td bgcolor='<%# IIF (DataBinder.Eval(Container.DataItem, "CategoryName") =
    "Confections","#ff0000","#ccffcc")%>'>

    Thanks very much for your help I tearing my hair out trying to make this
    work

    Regards

    Jim

    > Jim,
    >
    > Try this instead:
    > <td bgcolor='<%#(DataBinder.Eval(Container.DataItem, "CategoryName") ==
    > "something"?"#ff0000":"#ffffff"%>'>
    >
    > This assumes that you are in C#, in VB i think there is a immediate if
    > of IIf();
    >
    > HTH,
    > Chris
    >
    Jim Florence, Jun 24, 2006
    #5
    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. simon

    bgcolor of repeater row

    simon, May 31, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,528
    Eliyahu Goldin
    May 31, 2005
  2. sreenivasan alakappan

    non-form based databse application

    sreenivasan alakappan, Apr 2, 2004, in forum: C++
    Replies:
    6
    Views:
    344
    Christopher Benson-Manica
    Apr 8, 2004
  3. Replies:
    3
    Views:
    462
    Roger Upole
    Nov 7, 2008
  4. Nat
    Replies:
    0
    Views:
    132
  5. Íßêïò Ãêñ33ê
    Replies:
    39
    Views:
    467
    Grant Edwards
    Mar 11, 2013
Loading...

Share This Page