From: DavidC on 30 Mar 2010 16:24 I have a listview in an asp.net web page that I want to change the BackColor when a condition is met. I am checking for and finding the condition in the ItemDatabound event but I don't know what method I need to set the BackColor on a single row. I have done it in a GridView using the GridViewRow but I cannot find anything similar in a ListView control. Thanks. -- David
From: Gregory A. Beamer on 31 Mar 2010 11:27 "DavidC" <dlchase(a)lifetimeinc.com> wrote in message news:1EA4F98C-4325-4726-9A8B-5C5242F9383A(a)microsoft.com... > I have a listview in an asp.net web page that I want to change the > BackColor > when a condition is met. I am checking for and finding the condition in > the > ItemDatabound event but I don't know what method I need to set the > BackColor > on a single row. I have done it in a GridView using the GridViewRow but I > cannot find anything similar in a ListView control. Thanks. A list view does not have a row concept inherently, so you are setting up the row "condition" in your code somehow (or tagging an item to look more like a "row"). If you have not left any hooks to change background color, I.E. some type of container (div, table cell, span, etc), then you have no means of turning something black. As long as there is a cell being output, you have an opportunity to do something. Assuming you are setting up a table to create the concept of a "row" in a ListView (I am not sure why no GridView here, but I am sure you have a reason), there are a couple of ways to hack at this. 1. In the data binding method, grab inner controls until you find the container in question (table cell, div, span, etc). There are two things you can do then. a) dynamically add a backcolor property b) add information to match a CSS style (class is fairly easy) Of the two options, I would choose B. 2. Alter the flow so you dynamically output the HTML. If you invest at this level, it is probably better to create your own custom control (derived from whichever control is best for you, ListView or GridView?). I am not as fond of this option unless you have a good case for reuse of the methodology. If this is a single page that you are doing this on, it is a lot of work for a page. But, if you are using this methodology (conditional painting of background), this option is very useful. I would also consider, whichever route you go, that you make it so the condition can be met asynchronously and still paint (AJAX), which pretty much pushes you to the CSS methodology, as it is much easier to swap out CSS classes on the client side than whack into properties. At least that is my personal feeling on the matter. It also helps separate the content from the formatting, which means you can easily alter things going forward. It may be a paradigm shift for you. -- Peace and Grace, Greg Twitter: @gbworld Blog: http://gregorybeamer.spaces.live.com ************************************************ | Think outside the box! | ************************************************
|
Pages: 1 Prev: Request Current Next: Using javascript to check data in SQL server |