HTMLのselectタグを使用して作成された3つのドロップダウンボックスがあります。ページの読み込み時に、最初のボックスにはいくつかの名前があります。これで、最初のボックスの名前の1つをクリックすると、2番目のボックスにさらにいくつかの名前が表示され、2番目のボックスの名前をクリックすると、3番目のボックスにさらにいくつかの名前が表示されます。AJAXを使用してこれを達成するにはどうすればよいですか?ASP.NetとMSSQLServerを使用する必要がありますそれだけ。私はAJAXの完全な初心者であり、それについて自分自身を教育してきましたが、何もうまくいきません。私は1週間近くコードを探していました。w3schools.comを調べましたが、そのコードを試しても機能しませんでした。私を助けてください、そしてそれを機能させるために必要なもの、そして何がどこに行くのかを段階的に教えてください。締め切りが迫っていますが、それを機能させるための努力は終わりに近づいています。助けて!!
8902 次
1 に答える
7
3つのドロップダウンリストをUpdatePanelに配置し、updatepanelのそれぞれにトリガーを追加することをお勧めします。次に、値が変更されたら、ドロップダウンに再入力し、updatepanelに更新をプッシュさせます。また、値を送信する場合に備えて、セッション状態を保持します。
目の前にコンパイラはありませんが、必要に応じてコメントを投稿してください。明日コードを投稿します。
実例
Visual Studioとマスターページに付属している「従来のテンプレート」を使用しているので、コンテンツプレースホルダーを失礼します。しかし、これは私が何を意味するかを示すはずです:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="MultiDropDown.aspx.cs" Inherits="AppSettingsRetrieval.MultiDropDown" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
String[] options = new[] { "ABC", "DEF", "GHI", "JKL", "MNO", "PQR", "STU", "VWX", "YZA" };
foreach (String option in options)
{
this.DropDownList1.Items.Add(new ListItem(option, option));
}
}
}
public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList2.Items.Clear();
this.DropDownList2.Items.Add(new ListItem("--- Please Select One ---"));
String[] options = new[] { "123", "456", "789", "101", "112", "131", "415", "161", "718" };
foreach (String option in options)
{
var str = String.Format("{0} {1}", this.DropDownList1.SelectedValue, option);
this.DropDownList2.Items.Add(new ListItem(str, str));
}
this.DropDownList2.Enabled = true;
this.DropDownList3.Enabled = false;
}
public void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList3.Items.Clear();
this.DropDownList3.Items.Add(new ListItem("--- Please Select One ---"));
String[] options = new[] { "test", "testing", "tester", "foo", "bar", "foobar" };
foreach (String option in options)
{
var str = String.Format("{0} {1}", this.DropDownList2.SelectedValue, option);
this.DropDownList3.Items.Add(new ListItem(str, str));
}
this.DropDownList3.Enabled = true;
}
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
<ContentTemplate>
<fieldset>
<legend>Consecutive Dropdown List</legend>
<p>
Primary Filter:
<asp:DropDownList runat="server" ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="---Please Select One---" />
</asp:DropDownList>
</p>
<p>
Secondary Filter:
<asp:DropDownList runat="server" ID="DropDownList2" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" AutoPostBack="true" Enabled="false">
<asp:ListItem Text="---Please Select One---" />
</asp:DropDownList>
</p>
<p>
Final Filter:
<asp:DropDownList runat="server" ID="DropDownList3" Enabled="false">
<asp:ListItem Text="---Please Select One---" />
</asp:DropDownList>
</p>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
于 2011-03-07T07:40:16.130 に答える