Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add Color To List Item Dynamically C#

Posted on 2009-07-12
1
Medium Priority
?
622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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!
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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