Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
9 Points
29 Posts
May 02, 2012 03:13 PM|LINK
Hi,
I'll try and explain as best as i can, I am a "noob" so please bare with me.
I have a dropdown, I have set:
<asp:DropDownList CssClass="LogCboWidth" ID="cboProduct" AutoPostBack="true" OnTextChanged="GetSaveTypeDropDown" runat="server" TabIndex="5"> </asp:DropDownList>
So a function fires off when the DropDown Changes
C# protected void GetSaveTypeDropDown(object sender, EventArgs e) { cboType.Items.Clear(); cboRetained.Items.Clear(); cboReason.Items.Clear(); RetentionEntities myentities = new RetentionEntities(); ObjectResult<SaveTypeSelect_Result> SaveType = myentities.SaveTypeSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboType.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var type in SaveType) { cboType.Items.Add(new ListItem(type.SaveType.ToString(), type.SaveType.ToString())); } ObjectResult<RetainedListSelect_Result> RetList = myentities.RetainedListSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboRetained.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var ret in RetList) { cboRetained.Items.Add(new ListItem(ret.Retained.ToString(), ret.Retained.ToString())); } ObjectResult<ReasonsSelect_Result> reasons = myentities.ReasonsSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboReason.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var reas in reasons) { cboReason.Items.Add(new ListItem(reas.Reason.ToString(), reas.Reason.ToString())); } }
I'm using the entity framework along with stored procedures.
My page load populates "cboProduct":
if (!IsPostBack) { GetProductDropDown(); .... .... .... } protected void GetProductDropDown() { RetentionEntities myentities = new RetentionEntities(); ObjectResult<ProductSelect_Result> products = myentities.ProductSelect(); cboProduct.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var product in products) { cboProduct.Items.Add(new ListItem(product.Product.ToString(), product.ProductKey.ToString())); } }
The function works in the sense that when "cboProduct" changes it postbacks and runs the function, therefore populating the other dropdowns.
The issue is that the selected text in cboProduct always reverts back to the top selection when selecting one.
EG:
cboProducts may have:
Home
Motor
Pet
Travel
I chose "Pet" the other drops down populate correctly with Pet selected, but afterwards (i think once its posted back) "cboProduct" displays "Home".
I have tried to put in some breaks to try and find whats happenning with no luck.
Any assistance would be great.
JayMarvels
Member
9 Points
29 Posts
DropDown Behaviour when posting back
May 02, 2012 03:13 PM|LINK
Hi,
I'll try and explain as best as i can, I am a "noob" so please bare with me.
I have a dropdown, I have set:
<asp:DropDownList CssClass="LogCboWidth" ID="cboProduct" AutoPostBack="true" OnTextChanged="GetSaveTypeDropDown" runat="server" TabIndex="5">
</asp:DropDownList>
So a function fires off when the DropDown Changes
C# protected void GetSaveTypeDropDown(object sender, EventArgs e) { cboType.Items.Clear(); cboRetained.Items.Clear(); cboReason.Items.Clear(); RetentionEntities myentities = new RetentionEntities(); ObjectResult<SaveTypeSelect_Result> SaveType = myentities.SaveTypeSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboType.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var type in SaveType) { cboType.Items.Add(new ListItem(type.SaveType.ToString(), type.SaveType.ToString())); } ObjectResult<RetainedListSelect_Result> RetList = myentities.RetainedListSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboRetained.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var ret in RetList) { cboRetained.Items.Add(new ListItem(ret.Retained.ToString(), ret.Retained.ToString())); } ObjectResult<ReasonsSelect_Result> reasons = myentities.ReasonsSelect(Convert.ToInt32(cboProduct.SelectedValue)); cboReason.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var reas in reasons) { cboReason.Items.Add(new ListItem(reas.Reason.ToString(), reas.Reason.ToString())); } }I'm using the entity framework along with stored procedures.
My page load populates "cboProduct":
if (!IsPostBack) { GetProductDropDown(); .... .... .... } protected void GetProductDropDown() { RetentionEntities myentities = new RetentionEntities(); ObjectResult<ProductSelect_Result> products = myentities.ProductSelect(); cboProduct.Items.Add(new ListItem(string.Empty, string.Empty)); foreach (var product in products) { cboProduct.Items.Add(new ListItem(product.Product.ToString(), product.ProductKey.ToString())); } }The function works in the sense that when "cboProduct" changes it postbacks and runs the function, therefore populating the other dropdowns.
The issue is that the selected text in cboProduct always reverts back to the top selection when selecting one.
EG:
cboProducts may have:
Home
Motor
Pet
Travel
I chose "Pet" the other drops down populate correctly with Pet selected, but afterwards (i think once its posted back) "cboProduct" displays "Home".
I have tried to put in some breaks to try and find whats happenning with no luck.
Any assistance would be great.