Solved

Add Color To List Item Dynamically C#

Posted on 2009-07-12
1
615 Views
Last Modified: 2012-08-13
In the code below I am attempting to add a color to the text coming into the list item. I maybe writing this totally wrong. All I wanna do is depending on the "ProductId" I wanna change the color of the text in "Name".
For productid=2 want "Name" text to be bronze
For productid=3 want "Name" text to be silver
For productid=4 want "Name" text to be gold

for (int i = 0; i < dt.Rows.Count; i++)

        {

            // here 'images' corresponds to the folder in your application

            string imgsrc = "images/" + dt.Rows[i]["imageFileName"].ToString(); ;

            string value = dt.Rows[i]["ProductId"].ToString();

            ListItem item=new ListItem(String.Format("<img src=\"{0}\">" +  " "+dt.Rows[i]["Name"].ToString(), imgsrc), value);

             switch (value.ToString())

            { 

                case "2":

                    item.Attributes.CssStyle = 

                    break;

         

                case "3":

                    list.ForeColor = System.Drawing.Color.Silver;

                    break;

                  

                case "4":

                    list.ForeColor = System.Drawing.Color.Gold;

                    break;

                    
 

            

            }

            //list.Items.Add(new ListItem(String.Format("<img src=\"{0}\">" +  " "+dt.Rows[i]["Name"].ToString(), imgsrc), value));

            list.Items.Add(item);

            item=null;

           

        }

Open in new window

0
Comment
Question by:npl77
1 Comment
 
LVL 3

Accepted Solution

by:
redflair earned 500 total points
ID: 24838129
Try setting CSS attribute like  "Attributes.CssStyle.Add("color", "red")".
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now