Anandh
Anandh

Reputation: 167

Drop Down Control Issue in IE9,IE10. Selected Option not displayed in drop down box

I have a drop down control in my web page. That's viewed Collection Dictionary value. Here i added One Option value in top of the drop down list with enabled selected option using J query.since the newly one added using [j query] was selected in drop down box after page render except the IE9,IE10 browser.

Please find the sample code.

collection code:

Dictionary<string,string> PlatformList=new Dictionary<string,string>();
PlatformList.Add("asp","ASP.NET")
PlatformList.Add("aspnetmvc","ASP.NET MVC")
PlatformList.Add("wpf","WPF")
PlatformList.Add("silverlight","Silverlight")

Here now binded the collection with drop down.

View.cshtml

  @Html.DropDownList("platform", new SelectList(PlatformList, "Key", "Value"))

Now i have added new Option in the Drop down with enabled selected option Using Jquery.

$(document).ready(function(){
  $('#platform').prepend("<option  value='all'>All</option>");
        $("#platform").find('option:first').attr('selected', 'selected'); 

});

After page rendered, The newly added one" All Option in selective stage in drop down' This is worked in IE7,IE8,Mozilla,Chrome.

But In IE9,IE10 the "All" option not viewed in U drop down.but it locate the top of the list with selected but it hide status.the viewed option in drop down was next to the All option is"

<option val="all" selected="selected">All</option>==> not viewed in IE9,IE10
<option val="asp">ASP.NET</option>----> this is viewed in IE9,IE10 in case the above issue.

please suggest can this support IE9,IE10. if so means, please update the solution.

Upvotes: 0

Views: 2633

Answers (2)

fnagel
fnagel

Reputation: 702

Manually changing the index should work, too:

$( "#platform" )[ 0 ].selectedIndex = 0;

Upvotes: 0

Barmar
Barmar

Reputation: 780871

Try this:

$(document).ready(function(){
    $('#platform').prepend("<option  value='all'>All</option>");
    $("#platform option:selected").removeAttr('selected');
    $("#platform option:first").attr('selected', 'selected'); 
});

Your code is not removing the selected attribute from the original default, and multiple options with this attribute may be conflicting.

Upvotes: 1

Related Questions