Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

How to lock the drop down menu selecteditem.value?

I use asp.net and c#

I have a form which has a drop down list databind with a table in MSSQL 2005 DB

When I selected an item, it will be locked and cannot change the drop down selected item.

How can I do that?
Avatar of MrAgile
MrAgile
Flag of Australia image

hi There,

you can call a javascript function with an onchange event and then disable the dropdown list from the function.

or

You can call an event in the code behind of your page and then disable the dropdown list from there.

Sean
Hi techques,
So do you mean once your select the Item you want to lock it?
You can do something like this:

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList1.Enabled = false;
    }

But the problem will b..what if you selected a wrong value? you will need a button or some other control to Enable back the DDL.

If that above code does not meet your requirements please provide more info on what you are trying to achieve.
Avatar of techques
techques

ASKER

Hi

When I choose item on drop down list, it still enable.

Then, I add a breakpoint on this.clientid.Enabled = false;

Actually, it did not run that code when i select an item.


validateRequest="false" AutoEventWireup="true"
 
<asp:dropdownlist id=clientid runat="server" AutoPostBack="True" OnSelectedIndexChanged="clientid_SelectedIndexChanged"></asp:dropdownlist>
 
C# code
protected void clientid_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.clientid.Enabled = false;
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of guru_sami
guru_sami
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As I use aspx to include a ascx placeholder. The drop down list is in the ascx page.

Will it the reason not execute
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

and cannot exeute
this.DropDownList1.Enabled = false;

as the id of this.DropDownList1 has changed to ct_101.DropDownList1

if the dropdown is in ascx file then use the selectedIndexChanged code in the code behind of ascx file
Yes, I did use selectedIndexChanged code in the code behind of ascx file, but the code did not execute when i select an item in drop down list.

thats weird...
do you have AutoPostBack=true for the dropdownlist correct?
Can you post your markup and code-behind
it is ok now as i use button to lock and unlock to set the this.DropDownList1.Enabled = false; and true;

Thanks for help