2012-07-04 23 views

回答

2

在MaritalStaus DropDownList Selected Index已更改事件中,如果所選值與您的選項匹配,則啓用NoOfChild DropDownList。

protected void MaritalStaus_SelectedIndexChanged(object sender, EventArgs e)  
    { 
      //Match the selected value here : for Example: 
      if (MaritalStaus.SelectedValue.Equals("Divorced") || /*Other Comparisions */) 
      { 
      NoOfChild.Enabled = true; 
      } 
    } 
0

下拉列表列表項收集它們。每個ListItem具有文本。嘗試將文本設置爲「Divorced」並將其值設置爲「D」或更好地設置爲「1」之類的整數,類似於ID。如果您從數據庫中檢索它,您將從數據庫表中獲取這些文本/值。

讓孩子下拉Enabled = false默認,然後由ebad86的代碼片段解釋上述Enable = true的號。

0

級聯下拉的.aspx

<asp:DropDownList ID="ddlMaritalStatus" runat="server" AutoPostBack="true" 
     onselectedindexchanged="ddlMaritalStatus_SelectedIndexChanged"> 
    <asp:ListItem Text="" /> 
    <asp:ListItem Text="Widow" /> 
    <asp:ListItem Text="Divorced" /> 
    <asp:ListItem Text="Awaiting Divorce" /> 
</asp:DropDownList> 
<asp:DropDownList ID="ddlNoOfChildren" runat="server" Enabled="false"> 
    <asp:ListItem Text="1" /> 
    <asp:ListItem Text="2" /> 
    <asp:ListItem Text="3" /> 
    <!-- and so on --> 
</asp:DropDownList> 

aspx.cs

protected void ddlMaritalStatus_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    if (ddlMaritalStatus.SelectedItem.Text == "Widow") // if widow is selected 
     ddlNoOfChildren.Enabled = true; 
    else 
     ddlNoOfChildren.Enabled = false; 
} 
相關問題