Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 9th, 2012, 05:40 PM
Registered User
Points: 27, Level: 1
Points: 27, Level: 1 Points: 27, Level: 1 Points: 27, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2012
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
Default How to dynamically set a listview's backColor in code behind

Hello

Is there a way of dynamically changing the background colour for a whole row of a listview in the .cs file?

I have asp.net code which defines an item template as...

Code:
        <ItemTemplate >
        <%# addDateToListViewIfChanged() %>
            <tr  class="FixtureStyle" style="">
              <asp:Panel ID="RowPanel" runat="server">
            
                <td style="text-align:right">
                    <asp:Label ID="HomeTeam" runat="server" Text='<%# Eval("ClubName") %>' Width="160px"   />
                </td>
                <td style="width:20px; text-align:center">
                    <asp:Label ID="Versus" runat="server" Text=" v " />
                </td>
                <td>
                    <asp:Label ID="AwayTeam" runat="server" Text='<%# Eval("Expr1") %>' Width="160px"/>
                </td>
                <td style="text-align:right">
                    <asp:Label ID="HomeScoreLabel" runat="server" Text='<%# Eval("HomeScore") %>' Width="30px" />
                </td>
                <td style="width:18px; text-align:center">
                    <asp:Label ID="Dash" runat="server" Text = " - " />
                </td>
                <td>
                    <asp:Label ID="AwayScoreLabel" runat="server" Text='<%# Eval("AwayScore") %>' Width="30px"/>
                </td>
              </asp:Panel>
            </tr>
        </ItemTemplate>
...and I have code behind code which finds the data I want and highlights the labels correctly.

Code:
    protected void ResultsListView_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            // 1. Find the specific Label and check text value.
            Label hlbl = (Label)e.Item.FindControl("HomeTeam");
            Label albl = (Label)e.Item.FindControl("AwayTeam");
            Label hslbl = (Label)e.Item.FindControl("HomeScoreLabel");
            Label aslbl = (Label)e.Item.FindControl("AwayScoreLabel");
            Label vlbl = (Label)e.Item.FindControl("Versus");
            Label dlbl = (Label)e.Item.FindControl("Dash");
            Panel RPanel = (Panel)e.Item.FindControl("RowPanel");
            

            if (hlbl.Text == "Middle Ripsley" | albl.Text == "Middle Ripsley")
            {
                hlbl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                albl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                hslbl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                aslbl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                vlbl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                dlbl.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
                RPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#333333");
            }
        }
    }

Unfortunately, only the label parts of the row are highlighted, with the rest staying the original black, as shown below.


http://img.photobucket.com/albums/v6...chighlight.png


(note the pabel was added afterwards in the hope that I could set the background for the panel, but that didn't work either)


Is there a way of setting the whole row so it is highlighted?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically determining the name of an attribute-set Shadowgopher XSLT 1 July 17th, 2009 04:23 PM
how to set the backgound-color dynamically Neha XSLT 7 July 10th, 2008 07:17 AM
Dynamically set Button atrubute dijomonmd Javascript 1 June 8th, 2006 02:27 AM
Crystal - Set Y axis values dynamically vasanti Classic ASP Basics 0 February 14th, 2005 06:25 AM
Dynamically set selected attribute fs22 Javascript How-To 5 December 24th, 2004 04:10 PM



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.