?
Solved

Change Items styles in a DropDown Combo

Posted on 2005-03-08
8
Medium Priority
?
225 Views
Last Modified: 2008-02-01
Hello, I want to change the style of some items of a drop down list web control from the server side with the followintg example code:

------------------------------------------------------------------------------------------------------
liAux = new ListItem("TEST", "0");
liAux.Attributes.Add("bgcolor", "red");
Dropdownlist1.Items.Insert(0, liAux);
Dropdownlist1.Items[0].Text = Dropdownlist1.Items[0].Text +
                                                    liAux.Attributes.Count.ToString() +
                                                    liAux.Attributes["bgcolor"].ToString();
------------------------------------------------------------------------------------------------------

the result HTML code is the following:
------------------------------------------------------------------------------------------------------
<select name="Dropdownlist1" onchange="__doPostBack('Dropdownlist1','')" language="javascript" id="Dropdownlist1" class="cbGeoGreen11">
      <option value="0">TEST1red</option>

</select>
------------------------------------------------------------------------------------------------------

where's the bgcolor attribute of the option item???? but as you can see the text of the item contains the attribute so the item have the attribute... so the HTML should look like this:

------------------------------------------------------------------------------------------------------
<select name="Dropdownlist1" onchange="__doPostBack('Dropdownlist1','')" language="javascript" id="Dropdownlist1" class="cbGeoGreen11">
      <option value="0" bgcolor="red">TEST1red</option>

</select>
------------------------------------------------------------------------------------------------------

I have tried with CssClass with the same result.

Could anyone help me with this trouble?

Thanks in advance.

0
Comment
Question by:2much4u
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 13489898
i think some bug with web server control...use html drop downlist and make it run at server...
0
 

Author Comment

by:2much4u
ID: 13490679
a bug? do you really think that? everything is working fine in my app, and I've tested this example in two different servers.
0
 
LVL 15

Expert Comment

by:praneetha
ID: 13490693
it works..then u jst said..it does not set the bg color...

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:praneetha
ID: 13496872
so how did u fix it...
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13498693
2much4u,

Suggest you take a look at the EE Guidelines regarding grading standards.
What's the right grade to give?
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/help.jsp#hi73

And specifically this section:
<quote>
The use of a C in a vindictive manner is likely to be changed by a Moderator. You may not like the answer you get, and in some cases, and you may not like the way it is delivered, but if it is deemed to be accurate, no less than a B is an acceptable grade.
</quote>
0
 

Author Comment

by:2much4u
ID: 13504565
First of all, thanks for you comment acperkins, I should gave a B to the answer. How can I change it?

Second,

praneetha, I solved this with the following:

I changed

System.Web.UI.WebControls.DropDownList

by

System.Web.UI.WebControls.HtmlSelect

and making some minor changes in my HTML code, changing this:

<asp:DropDownList id=dlTEST runat="server" DataSource="<%# dsTEST %>" DataMember="Table" DataTextField="ID_TEST" DataValueField="ID_TEST"></asp:DropDownList>

to:

<select id="dlTEST" runat="server" DataValueField="ID_TEST" DataTextField="D_TEST" DataMember="Table" DataSource="<%# dsTEST %>" onchange="__doPostBack('dlADM2','')" language="javascript" class="cbGeoGreen11"></select>

in CodeBehind everything works in the same way, excepts the way of get the value of the selected item that changes from

dlTEST.SelectedValue;

to:

dlTEST.Items[dlTEST.SelectedIndex].Value

and finally, my target that was to distinguish some items of the list was solved with the following:

ListItem li = dlTEST.Items.FindByValue(VALUE);
if (li != null) li.Attributes.Add("class", "opDarkGreen11");


I hope that this will be helpful for other users.
thanks for your help.
0
 
LVL 15

Expert Comment

by:praneetha
ID: 13506742
Thank you acperkins.

glad you could solve it.

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13506788
>>First of all, thanks for you comment acperkins, I should gave a B to the answer. How can I change it?<<
See here:
Can I get a grade changed?
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/help.jsp#hi18
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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