微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

根据服务器端asp.net中的其他dopdown值更改重置下拉值

如何解决根据服务器端asp.net中的其他dopdown值更改重置下拉值

我有一个下拉值,称为“雇主”,“职位”和“部门”。 根据雇主选择的值,我正在更改其他两个的值。 例如,如果用户在Employerthen位置选择不可用,部门将自动选择为不可用。这工作正常。 还有另一件事是,如果我决定设置我的雇主值,一次在雇主中选择不可用之后,职位和部门值也将被清除。这也很好。

但是出现问题,当我用Ctrl + A选择Employer并通过退格键删除值并单击页面中下拉区域之外时,显示错误
错误 {“输入字符串的格式不正确。”}

在我的page_load事件中,我添加了它。

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);
        }
    }

我还添加 ddlAddEmployer_OnSelectedindexChanged 视图和CS文件

<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文件

protected void ddlAddEmployer_OnSelectedindexChanged(object sender,EventArgs e)
    {
        try
        {
            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);
        }
    }

我很困惑。需要针对该问题的相关解决方案。 最好的问候,

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。