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?
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?
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_SelectedInde xChanged(o bject 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.
So do you mean once your select the Item you want to lock it?
You can do something like this:
protected void DropDownList1_SelectedInde
{
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.
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.
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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_SelectedInde xChanged(o bject sender, EventArgs e)
and cannot exeute
this.DropDownList1.Enabled = false;
as the id of this.DropDownList1 has changed to ct_101.DropDownList1
Will it the reason not execute
protected void DropDownList1_SelectedInde
and cannot exeute
this.DropDownList1.Enabled
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
ASKER
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
do you have AutoPostBack=true for the dropdownlist correct?
Can you post your markup and code-behind
ASKER
it is ok now as i use button to lock and unlock to set the this.DropDownList1.Enabled = false; and true;
Thanks for help
Thanks for help
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