C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Adding attributes such as backgorund color, forecolor to the particular item of a dropdownlist


Posted Date: 27 Jan 2008    Resource Type: Articles    Category: Web Applications

Posted By: DhivyaSelvadurai       Member Level: Gold
Rating:     Points: 10



<H2>Setting Background color and Fore color of a particular item</H2>

To be frank if u try to set a background color or a fore color of a particular item in a web control dropdownlist based on some conditions using "Dropdownlist1.Item[0].Attributes.CssStyle.Add", the change will not reflect in the page while executing. To handle this, Use a html dropdownlist <Select id=Select1></Select>, make this as a server control by right click the control.


//html dropdownlist
Select1.Items.Add("1");
Select1.Items.Add("2");
Select1.Items.Add("3");
Select1.Items.Add("4");
Select1.Items[1].Attributes.CssStyle.Add("BACKGROUND-COLOR","green");
Select1.Items[3].Attributes.CssStyle.Add("COLOR","red");
//to execute onchange event on selected index chage [auto postback]
Select1.Attributes.Add("onchange","__doPostBack('Select1','')");

//web control dropdownlist
DropDownList1.Items.Add("0");
DropDownList1.Items.Add("1");
DropDownList1.Items.Add("2");
DropDownList1.Items.Add("3");
DropDownList1.Items.Add("4");
DropDownList1.Items[2].Attributes.CssStyle.Add("BACKGROUND-COLOR","green");
DropDownList1.Items[4].Attributes.CssStyle.Add("COLOR","red");
//This will not reflect..No color will be set for a particular item.


Try this...Sometimes u may come across this situation of handling different colors for different items of a dropdownlist.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Adding style to dropdown item  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Shopping Cart,Datatable in Session
Previous Resource: Web Services
Return to Discussion Resource Index
Post New Resource
Category: Web Applications


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

teleconferencing

Contact Us    Privacy Policy    Terms Of Use