以下のコードを試してください。
<asp:DropDownList runat="server" AutoPostBack="true" ID="ddlCategories" OnSelectedIndexChanged="ddlCategories_SelectedIndexChanged">
<asp:ListItem Text="All" Value="All" />
<asp:ListItem Text="Nokia" Value="Nokia" />
<asp:ListItem Text="Samsung" Value="Samsung" />
</asp:DropDownList>
<asp:DropDownList runat="server" AppendDataBoundItems="true" ID="ddlSubCategories">
<asp:ListItem Text="All" Value="All" />
</asp:DropDownList>
データベースを使用していないため、値をハードコーディングする必要があります。
protected void ddlCategories_SelectedIndexChanged(object sender, EventArgs e)
{
ddlSubCategories.Items.Clear();
if (string.Compare(ddlCategories.SelectedValue, "Nokia", true) == 0)
{
ddlSubCategories.Items.Add(new ListItem("3310", "3310"));
ddlSubCategories.Items.Add(new ListItem("N95", "N95"));
}
else if (string.Compare(ddlCategories.SelectedValue, "Samsung", true) == 0)
{
ddlSubCategories.Items.Add(new ListItem("Galaxy Ace", "Galaxy Ace"));
ddlSubCategories.Items.Add(new ListItem("Galaxy SII", "Galaxy SII"));
}
ddlSubCategories.Items.Insert(0, new ListItem("All", "All"));
}
それが役に立てば幸い。javascriptルートに行きたい場合は、以下のリンクを見つけてください。
別のドロップダウンの選択に基づいて1つのドロップダウンにデータを入力します