C# UpdatePanel没有更新回来

C# UpdatePanel没有更新回来,c#,asp.net,C#,Asp.net,表单中有下拉列表和复选框列表。 DropDownList中的值应根据选项复选框列表的不同而变化 当您选择(单击)元素时,DropDownList中的值会更改, 如果取消勾选返回没有改变(它保持为高) aspx: Risk: <asp:UpdatePanel ID="UpRisk" runat="server" UpdateMode="always"> <ContentTemplate> <asp:DropDownList ID="ddlRiskLevel"

表单中有
下拉列表
复选框列表

DropDownList中的值应根据选项复选框列表的不同而变化
当您选择(单击)元素时,DropDownList中的值会更改,
如果取消勾选返回没有改变(它保持为高)
aspx:

 Risk:
<asp:UpdatePanel ID="UpRisk" runat="server" UpdateMode="always">
 <ContentTemplate>
   <asp:DropDownList ID="ddlRiskLevel" runat="server" Enabled="false" AutoPostBack="True">
     <asp:ListItem Text="Low" Value="1" Selected="True" />
     <asp:ListItem Text="High" Value="2" />
   </asp:DropDownList>
 </ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel24" runat="server" UpdateMode="always">
   <ContentTemplate>
         Sign:
      <asp:CheckBoxList ID="chbList_Risks" runat="server">
        <asp:ListItem> Sign1 </asp:ListItem>
        <asp:ListItem> Sign2 </asp:ListItem>
        <asp:ListItem> Sign3 </asp:ListItem>
      </asp:CheckBoxList>
    </ContentTemplate>
</asp:UpdatePanel>  
protected void Page_Load(object sender, EventArgs e)
{
   foreach (ListItem item in chbList_Risks.Items)
   {
       if (item.Selected)
        ddlRiskLevel.SelectedValue = "2";
   }
}

您没有为取消选中而执行任何操作,请尝试下面的操作

foreach (ListItem item in chbList_Risks.Items)
   {
       if (item.Selected)
       {
        ddlRiskLevel.SelectedValue = "2";
        break;
       }
       else
      {
       ddlRiskLevel.ClearSelection();
      }
   }

您没有为取消选中而执行任何操作,请尝试下面的操作

foreach (ListItem item in chbList_Risks.Items)
   {
       if (item.Selected)
       {
        ddlRiskLevel.SelectedValue = "2";
        break;
       }
       else
      {
       ddlRiskLevel.ClearSelection();
      }
   }

试试这段代码,效果很好

foreach (System.Web.UI.WebControls.ListItem item in chbList_Risks.Items)
         {
                        if (item .Selected == true)
                        {
                            value = item .Text;

                            if (value == "ABC")
                            {
                               ddlRiskLevel.SelectedValue = "2";
                            }
                        }
                        else
                        {
                            value = item .Text;

                            if (value == "XYZ")
                            {
                                 ddlRiskLevel.ClearSelection();
                            }
                        }
        }

试试这段代码,效果很好

foreach (System.Web.UI.WebControls.ListItem item in chbList_Risks.Items)
         {
                        if (item .Selected == true)
                        {
                            value = item .Text;

                            if (value == "ABC")
                            {
                               ddlRiskLevel.SelectedValue = "2";
                            }
                        }
                        else
                        {
                            value = item .Text;

                            if (value == "XYZ")
                            {
                                 ddlRiskLevel.ClearSelection();
                            }
                        }
        }