Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 dropdown list with sql value that have initial value too that second drop down list changes after selecting from first drop down list so I should clear second drop down list value after changes happen in fist one but after clearing first drop down list my intial value doesn't appear what should I do in my behind code to show my initial value after clearing?

first dropdown:
<asp:dropdown ID="OrderNo" runat="server"   MaxLength="0" style="display: inline;"  AppendDataBoundItems="True" DataSourceID="OrderNo_SqlDS" DataTextField="OrderNo"  DataValueField="OrderNo" onselectedindexchanged=" OrderNo_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem Text="--Select One--" Value="" /></asp:dropdown> 



Second dropdown:

<asp:dropdown ID="Part" runat="server"   MaxLength="0" style="display: inline;"  AppendDataBoundItems="True" DataSourceID="Part_SqlDS" DataTextField="Part"  DataValueField="Part" onselectedindexchanged=" Part_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem Text="--Select One--" Value="" /></asp:dropdown>


and in my behind code:
protected void OrderNo_SelectedIndexChanged(object sender, EventArgs e)     
{ 
Part.Items.Clear(); 
Part.DataBind();  
   }
Posted
Comments
BillWoodruff 19-Feb-12 10:42am    
"but after clearing first drop down list:" this does not make sense to me: isn't there always going to be a selection in the first drop down list: and only the contents of the second drop-down list need to cleared/changed ?
kitykity 20-Feb-12 1:47am    
yes after changing in first drop down second drop down has last value + new value so I want to clear last value to see just new value

1 solution

Dear Friend,

What I understood from your question is that you want to retrieve the initial value of the first drop-down if this is the case then you just have to save the initial value in the hidden field before changing or clearing it (in your case) and then select the same field again after binding data to the first drop down like :-

//Before changing or clearing the drop down data
HiddenField hdnID= ddlFirst.SelectedValue;
//After binding data again
ddlFirst.SelectedValue=hdnID.Value;


I hope this will solve your problem.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900