I am using
TextBox.ReadOnly = false;
for readonly.
How can i fix it on DropDownList?
I use Enabled = false properties like...
TextBox.Enabled = false;
DropDownList.Enabled = false;
but, after that css class not call in this both control at run-time.
Please give me any properties like "ReadOnly".
As disabled dropdownlist data cannot be read in postback. So as a workaround do not disable it, but first clear dropdownlist and then bind only already selected item.
When you disable the dropdownlist by setting Disabled=true; or Enabled=false (whatever the case is), you can also change the Font properties to make it easier to read. You can set other properties such as Border, BorderStyle, etc, etc.
All you need to do is use the enabled property in the control and set it as true to enable and false to disable it.
Cause SelectedValue will give you the value stored for current selected item in your dropdown and SelectedItem. Value will be Value of the currently selected item.
There is no readonly property for DropDownList
in asp.net
Try using:
<asp:DropDownList ID="DropDownList1" runat="server" Enabled="False">
</asp:DropDownList>
Or change it at runtime:
DropDownList1.Enabled=false;
and change it's css class as well.
DropDownList1.CssClass = "class";
Another way:
Code Behind: Just add attribute disabled
DropDownList1.Attributes.Add("disabled", "disabled");
Client Side:
$("#DropDownList1").attr("disabled","disabled");
JS FIDDLE
Use a panel as with Enabled="false" and put your control inside:
<asp:Panel ID="pnlname" runat="server" Enabled="false">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</asp:Panel>
As disabled dropdownlist data cannot be read in postback. So as a workaround do not disable it, but first clear dropdownlist and then bind only already selected item.
ListItem item = DropDownList.SelectedItem;
DropDownList.Items.Clear();
DropDownList.Items.Add(item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With