SportsName および Category という名前の 2 つのドロップダウンリストがあります。SportsName リストで選択した項目にカテゴリ リストを依存させたい。これは私がこれを行うために使用したコードですが、機能していません
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SportsName.Items.Insert(0,new ListItem("Select", string.Empty));
SportsName.Items.Insert(1,new ListItem("Badminton", "Badminton"));
SportsName.Items.Insert(2,new ListItem("Tennis", string.Empty));
SportsName.Items.Insert(3,new ListItem("Table Tennis", string.Empty));
SportsName.Items.Insert(4,new ListItem("Swimming", string.Empty));
SportsName.Items.Insert(5,new ListItem("Sports Ball", string.Empty));
SportsName.Items.Insert(6,new ListItem("Bats", string.Empty));
SportsName.Items.Insert(7,new ListItem("Sports Cap", string.Empty));
SportsName.Items.Insert(8,new ListItem("Gym Equipments", string.Empty));
SportsName.Items.Insert(9,new ListItem("Darts", string.Empty));
SportsName.Items.Insert(10,new ListItem("Billards", string.Empty));
SportsName.Items.Insert(11,new ListItem("Fitness", string.Empty));
SportsName.Items.Insert(12,new ListItem("Sports Medicine", string.Empty));
SportsName.Items.Insert(13,new ListItem("Contact Sports", string.Empty));
SportsName.Items.Insert(14,new ListItem("Outdoor", string.Empty));
SportsName.Items.Insert(15,new ListItem("LifeSyle", string.Empty));
SportsName.Items.Insert(16,new ListItem("Shoes and Apprel ", string.Empty));
SportsName.Items.Insert(17,new ListItem("Hockey", string.Empty));
SportsName.Items.Insert(18,new ListItem("Golf", string.Empty));
SportsName.SelectedIndex=0;
}
}
protected void Category_SelectedIndexChanged(object sender, EventArgs e)
{
if (SportsName.SelectedIndex == 1)
{
Category.Items.Clear();
Category.Items.Add(new ListItem("Rackets", string.Empty));
Category.Items.Add(new ListItem("Sets", string.Empty));
Category.Items.Add(new ListItem("Shuffle", string.Empty));
}
if (SportsName.SelectedIndex == 2)
{
Category.Items.Clear();
Category.Items.Add(new ListItem("Golf", string.Empty));
}
if (SportsName.SelectedIndex == 3)
{
Category.Items.Clear();
Category.Items.Add(new ListItem("Ball", string.Empty));
}
}
これを行う正しい方法を教えてください。バドミントンを選択すると、国と都市の場合と同様に、そのすべての機器が2番目のドロップダウンリストに表示されます。
HTMLコード
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<style type="text/css">
.style8
{
width: 100%;
}
.style9
{
width: 215px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table class="style8">
<tr>
<td class="style9">
Sports Name</td>
<td>
<asp:DropDownList ID="SportsName" runat="server" AutoPostBack="True"
Height="26px" Width="126px">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Category</td>
<td>
<asp:DropDownList ID="Category" runat="server" Height="26px"
onselectedindexchanged="Category_SelectedIndexChanged" Width="126px">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Sub Category</td>
<td>
<asp:DropDownList ID="SubCategory" runat="server" Height="26px" Width="126px">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Brand</td>
<td>
<asp:DropDownList ID="Brand" runat="server" Height="26px" Width="128px">
</asp:DropDownList>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Image</td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
MRP</td>
<td>
<asp:TextBox ID="mrp" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Our Price</td>
<td>
<asp:TextBox ID="ourprice" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
You Save</td>
<td>
<asp:TextBox ID="yousave" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Shipping Charges</td>
<td>
<asp:TextBox ID="shippingcharges" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
Expected Delivery</td>
<td>
<asp:TextBox ID="expecteddelivery" runat="server"></asp:TextBox>
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
<asp:Button ID="submit" runat="server" Text="Button" />
</td>
<td>
<asp:Button ID="reset" runat="server" Text="Button" />
</td>
<td>
</td>
</tr>
<tr>
<td class="style9">
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</asp:Content>