Solved

Add Color To List Item Dynamically C#

Posted on 2009-07-12
1
616 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 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

12 Experts available now in Live!

Get 1:1 Help Now