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 FlorenceInstead 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
"Dean" <Dean@.discussions.microsoft.com> wrote in message
news:79F7A0BD-A3ED-4605-8CE4-89DACF298D04@.microsoft.com...
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,
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" <chris@.cubed-c.com> wrote in message
news:1151142480.516385.115290@.m73g2000cwd.googlegr oups.com...
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
0 comments:
Post a Comment