Hi all.. I need to make my dropdownlist disabled (none can change value or it should be read only)..which property should I use as readonly for dropdownlist is not working for me..
PHMO..

Dani AI

Generated

Good call by : DropDownList does not support a ReadOnly state. In HTML, a select has no readonly attribute, so the usual way to prevent changes is to disable it. One gotcha to be aware of: browsers do not submit disabled fields. On a normal postback, ASP.NET restores the selected value from ViewState, but you will not see that value in Request.Form, and a cross-page post will not include it. Also, AutoPostBack/SelectedIndexChanged will not fire while it is disabled.

If you need the control to be effectively read-only but still submit the value, render the value and hide the picker. This keeps the form data intact and avoids the disabled-postback caveat:

<asp:Label ID="ColorDisplay" runat="server" />
<asp:HiddenField ID="ColorValue" runat="server" />
// e.g., in Page_PreRender
ColorDisplay.Text = DropDownList1.SelectedItem.Text;
ColorValue.Value  = DropDownList1.SelectedValue;
DropDownList1.Visible = false; // hide the picker; form posts ColorValue

Another lightweight pattern is to leave the control enabled but make all non-selected items unselectable. Users cannot change the choice, and the selected value still posts:

foreach (ListItem item in DropDownList1.Items)
{
    item.Enabled = item.Selected; // only the current choice is enabled
}

Practical notes:

  • If you later re-enable interaction, flip Visible = true (or re-enable the items) before the page renders.
  • Do not rely on client-side hacks alone; keyboard users can still change focus/selection unless you handle both mouse and keyboard input.
  • If you must show it disabled for visual clarity and still submit the value to another page, mirror the selection into a HiddenField as shown above.

Recommended Answers

All 8 Replies

Set DropDownList1.Enabled=false.

Set DropDownList1.Enabled=false.

thanks for your reply..yes it works for me..
regards.

>but it is not working out there..some other way to do so??

I want to know why it is not working. Please post your code.

To disable the dropdownlist, set the disable property yes


Hi all.. I need to make my dropdownlist disabled (none can change value or it should be read only)..which property should I use as readonly for dropdownlist is not working for me..
PHMO..

change the enable propery to false..

>but it is not working out there..some other way to do so??

I want to know why it is not working. Please post your code.

it has worked... thanks

Hi

Refer the following code for how to disable a dropdownlist in asp.net

Hi

To solve the issue of to disable a dropdownlist in asp.net.you can refer following code.

<asp:DropDownList ID="DropDownList1" runat="server" Enabled="False">
</asp:DropDownList>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.