一:后台加载DropDownList
后台查询配置表显示内容并赋值
var list = ShuiWuPeiZhi.FindAll("", "", "", 0, 0);
if (list != null && list.Count() > 0)
{
YWContent.DataSource = list;
YWContent.DataTextField = "YW";
YWContent.DataValueField = "YW";
YWContent.DataBind();
}
前台:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="YWContent" OnSelectedIndexChanged="SelectProductTypeChange" AutoPostBack="true" runat="server" CssClass="form-control bg" Enabled="false">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
**
二:后台change事件,及局部刷新
事件方法:需要配置
AutoPostBack="true"才能激发后台点击方法
OnSelectedIndexChanged="SelectProductTypeChange"
后台change方法:
protected void SelectProductTypeChange(object sender, EventArgs e)
{
var list = ShuiWuPeiZhi.FindByName("YW", YWContent.SelectedValue);
TaxRate.Text = list.SL;
}
局部刷新:控件要放在UpdatePanel 里面才会有用,否则会整个页面都刷新。
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
//控件写在这里
</ContentTemplate>
</asp:UpdatePanel>
Web.config配置:
局部刷新还是无效时,在配置文件将下面这段配置去掉
<xhtmlConformance mode="Legacy"/>