Answered by:
dropdown value reset based on other dopdown value change in server side asp.net

Question
-
User355715116 posted
Dear concern,
I have a drop down value called Employer, position and department. Based on Employerselected value I am changing value of others two. Ex.if user selects Not Available at Employerthen position and department will be auto selected as Not Available. And this is working fine. And another thing is after selecting Not Available in Employer once if I decided to set my Employer value then Position and department value will be cleared too.This is working fine also.</div> </div> <div class="postcell post-layout--right"> <div class="s-prose js-post-body" itemprop="text">But problem occurs, when I am selecting Employer with Ctrl + A and deleting the value by backspace and clicking outside of dropdown area in my page ,its showing error.
And the error is {"Input string was not in a correct format."}In my page_load event I've added this.
protected void Page_Load(object sender, EventArgs e) { try { if (ddlAddEmployer.Text == string.Empty) { ddlAddPosition.Text = "Select/type a position"; txtAddClinicalArea.Text = string.Empty; txtLocationAddNumber.Text = string.Empty; } } catch (Exception ex) { AddWorkHistoryRadAjaxPanel.Alert("An Error has occured"); ((test.Global_asax)this.Context.ApplicationInstance).Application_Error(ex); } }
I have a drop down value called Employer, position and department. Based on Employerselected value I am changing value of others two. Ex.if user selects Not Available at Employerthen position and department will be auto selected as Not Available. And this is working fine. And another thing is after selecting Not Available in Employer once if I decided to set my Employer value then Position and department value will be cleared too.This is working fine also.
But problem occurs, when I am selecting Employer with Ctrl + A and deleting the value by backspace and clicking outside of dropdown area in my page ,its showing error.
And the error is {"Input string was not in a correct format."}In my page_load event I've added this.
protected void Page_Load(object sender, EventArgs e) { try { if (ddlAddEmployer.Text == string.Empty) { ddlAddPosition.Text = "Select/type a position"; txtAddClinicalArea.Text = string.Empty; txtLocationAddNumber.Text = string.Empty; } } catch (Exception ex) { AddWorkHistoryRadAjaxPanel.Alert("An Error has occured"); ((test.Global_asax)this.Context.ApplicationInstance).Application_Error(ex); } }
I am also adding my ddlAddEmployer_OnSelectedIndexChanged view and cs file
<telerik:RadComboBox ID="ddlAddEmployer" runat="server" name="ddlAddEmployer" AutoPostBack="True" AllowCustomText="false" EmptyMessage="Select a Company" EnableLoadOnDemand="true" OnClientBlur="OnClientBlurHandler" EnableVirtualScrolling="true" DropDownAutoWidth="Disabled" DropDownWidth="380px" OnSelectedIndexChanged="ddlAddEmployer_OnSelectedIndexChanged" ShowMoreResultsBox="true" Skin="WebBlue" class="ddlAddEmployer" Width="250px"> <CollapseAnimation Duration="200" Type="OutQuint" /> <WebServiceSettings Method="PopulateRadComboInstitutionWithVirtual" Path="AddWorkHistory.aspx" /> </telerik:RadComboBox>
cs file:
DataTable dtEmployer = InstitutionManager.GetInstitutionById(Convert.ToInt32(ddlAddEmployer.SelectedValue.ToString())); if (dtEmployer != null && dtEmployer.Rows.Count > 0 && dtEmployer.Rows[0]["InstituteID"].ToString() != "" && dtEmployer.Rows[0]["InstituteName"].ToString() != "") { string institutionName = dtEmployer.Rows[0]["InstituteName"].ToString(); if (institutionName.Equals(Utility.NOTAVAILABLE)) { DataTable dtPosition = PositionManager.GetPositionByName(institutionName); if (dtPosition != null && dtPosition.Rows.Count > 0) { int positionId = Convert.ToInt32(dtPosition.Rows[0]["PositionID"].ToString()); string positionName = dtPosition.Rows[0]["PositionName"].ToString(); ddlAddPosition.Text = positionName; ddlAddPosition.SelectedValue = positionId.ToString(); ddlAddPosition_OnSelectedIndexChanged(ddlAddPosition, null); } } else { ddlAddPosition.Text = "Select/type a position"; txtAddClinicalArea.Text = string.Empty; txtLocationAddNumber.Text = string.Empty; } } } catch (Exception ex) { AddWorkHistoryRadAjaxPanel.Alert("An Error has occured"); ((test.Global_asax)this.Context.ApplicationInstance).Application_Error(ex); } }
I am pretty much confused.Need a relevant solution regarding that issue. Best Regards,
Tuesday, September 8, 2020 12:26 PM
Answers
-
User1535942433 posted
Hi mazharul007,
Accroding to your description and codes,I couldn' reproduce your problems.Your codes post us are incomplete.
Do you have delete combobox Employer?Your problem is wrong string format.I suggest you could breakpoint and debug at the selectedchanged event and check which lines have errors.
Best regards,
Yijing Sun
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, September 9, 2020 8:14 AM