[英]selecting data from dropdown without refreshing the page
在我的應用程序中,當我從下拉列表(ddlcategory)中選擇類別時,數據將綁定在純度下拉列表(ddlpurity)中。但是頁面正在刷新。所以我使用了更新面板來解決此(頁面刷新)問題。選擇ddlcategory中的數據時,數據未綁定到ddlpurity。如何在不刷新頁面的情況下將數據綁定到ddlpurity。
ASP設計頁面
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:Asyncpostbacktrigger controlid="ddlcategory" eventname="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="ddlcategory" class="form-control txtboxmargin validate[required]" runat="server"
AutoPostBack="True" onselectedindexchanged="ddlcategory_SelectedIndexChanged" AppendDataBoundItems="True">
<asp:ListItem Value="">--select category--</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:DropDownList ID="ddlpurity"
class="form-control txtboxmargin" AutoPostBack="True" runat="server"
onselectedindexchanged="ddlpurity_SelectedIndexChanged">
</asp:DropDownList>
C#代碼:
protected void ddlcategory_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlcategory.SelectedItem.Text == "Gold")
{
BindDDLGoldPurity();
lblheadpurity.Text = "ADD GOLD PURITY";
txtsalesrate.ReadOnly = true;
}
if (ddlcategory.SelectedItem.Text == "Silver")
{
BindDDLSilverPurity();
lblheadpurity.Text = "ADD SILVER PURITY";
txtsalesrate.ReadOnly = true;
}
if (ddlcategory.SelectedItem.Text == "Gemstones")
{
txtsalesrate.ReadOnly = false;
txtsalesrate.Text = "";
ddlpurity.Items.Clear();
}
}
將AutoPostBack =“ False”設置為擺脫刷新行為。
您應該將兩個控件都包裝在UpdatePanel
。
在第二部分。 去掉
AutoPostBack="true"
從您的DropDownList
。
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server" ID="UpdatePanel" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlcategory" EventName="SelectedIndexChanged" />
</Triggers>
<ContentTemplate>
<asp:DropDownList ID="ddlcategory" class="form-control txtboxmargin validate[required]"
runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlcategory_SelectedIndexChanged"
AppendDataBoundItems="True">
<asp:ListItem Value="">--select category--</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlpurity" class="form-control txtboxmargin" AutoPostBack="True"
runat="server" OnSelectedIndexChanged="ddlpurity_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
您也可以使用javascript / jquery執行數據庫請求。
見參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.