Link to home
Start Free TrialLog in
Avatar of npl77
npl77

asked on

Add Color To List Item Dynamically C#

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

ASKER CERTIFIED SOLUTION
Avatar of redflair
redflair

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial