0

I am using an asp.net dropdownlist it contains 5 values the sample code is as follows

<asp:DropDownList ID="ddlSampledropdown" runat="server" Width="250px">
     <asp:ListItem Value="0" title="--Select--">--Select--</asp:ListItem>
     <asp:ListItem Value="1" title="Alpha">Alpha</asp:ListItem>
     <asp:ListItem Value="2" title="Bravo">Bravo</asp:ListItem>
     <asp:ListItem Value="3" title="Charlie">Charlie</asp:ListItem>
     <asp:ListItem Value="4" title="Delta">Delta</asp:ListItem>
     <asp:ListItem Value="5" title="Echo">Echo</asp:ListItem>
</asp:DropDownList>

I want to set the dropdownlist as disabled and set the selected text as alpha how can i do this with the help of a javascript in asp.net 2003

I made it as disabled but was unable to set the dropdownlist selected value

1
  • 1
    wooow where did you find asp.net 20003? you are about 18.000 years ahead?! Commented Sep 15, 2011 at 10:19

2 Answers 2

1

with JQuery, to select Alpha:

$("#ddlSampledropdown").val('1');

and to disable the control:

$("#ddlSampledropdown").attr("disabled", true);

sources:

Change the selected value of a drop-down list with jQuery

Disable drop down box on radio button click

Sign up to request clarification or add additional context in comments.

1 Comment

Most likely (unless he's on 4.0), his dropdown's id will not be 'ddlSampledropdown'. You might want to change your selector to something like '[id$=ddlSampledropdown]' instead, or use inline script to get the correct ClientId value.
1

Using classic Javascript, you may consider doing something like this. Note: obtain the correct client Id for your drop down.

var mydropdown= document.getElementById("ctl00_ctl00_<clientIdForDropdown>");
mydropdown.options[1].selected="selected";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.