【发布时间】:2015-07-07 11:15:18
【问题描述】:
在我的应用程序中,当我从下拉列表(ddlcategory)中选择类别时,数据将绑定在纯度下拉列表(ddlpurity)中。但是页面正在刷新。所以我使用更新面板来解决这个问题(页面刷新) problem.Now the data is not binding to the ddlpurity ,when data from ddlcategory is selected.How can i bind the data to ddlpurity without refreshing the page.
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();
}
}
【问题讨论】:
-
将它们放在同一个更新面板中
-
正如@Jeremy 所说,您需要在更新面板中添加
dropdownlist。并且在下拉列表的其他部分设置 AutoPostBack=false -
但如果我添加标签(lblcategory,lblpurity),它会显示“扩展器不能位于与其扩展的控件不同的 UpdatePanel 中。”