在我的应用程序中,当我从下拉( not类别)中选择类别时,数据将绑定在纯度下拉(not.But) refreshing.So中--我使用更新面板来解决这个(页面刷新) problem.Now --数据不绑定到not纯度,当来自not类别的数据是selected.How时,可以将数据绑定到not纯度而无需刷新页面。
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();
}
}发布于 2015-07-07 11:19:21
设置AutoPostBack="False“以消除刷新行为。
发布于 2015-07-07 11:27:11
您应该将两个控件包装在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执行数据库请求。
见参考文献
https://stackoverflow.com/questions/31267050
复制相似问题