html中的服务器控件
在asp.net框架中有一个asp:ScriptManager控件用此控件可进行html页面的局部刷新。
代码如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14<asp:ScriptManager ID="ScriptManager2" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div>
<label>库别:</label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
</div>
<div>
<label>区域:</label>
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>
<label>注意:该区域是与上选库别相关联的</label>
</div>
</ContentTemplate>
</asp:UpdatePanel>
csharp后台控制html中的前端局部刷新代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
RegionDC regionDC = new RegionDC();
DataSet ds2 = regionDC.getRegion_nameBySub_name(DropDownList1.Items[DropDownList1.SelectedIndex].Text);
int count = ds2.Tables[0].Rows.Count;
if (ds2 != null)
{
DropDownList2.DataSource = ds2.Tables[0].DefaultView;
DropDownList2.DataValueField = "region_key";
DropDownList2.DataTextField = "region_name";
DropDownList2.DataBind();
}
else
PageUtil.showAlert(this, "区域载入出错!");
DropDownList2.Items.Insert(0, "--选择区域--");
}
下拉菜单初始化绑定1
2
3
4
5
6
7
8
9
10
11private void BindDrop()
{
SubinventoryDC subDC = new SubinventoryDC();
DataSet ds1 = subDC.getAllUsedSubinventory_name();
DropDownList1.DataTextField = "subinventory_name";
DropDownList1.DataValueField = "subinventory_key";
DropDownList1.DataSource = ds1.Tables[0].DefaultView;
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--选择库别--"));
DropDownList2.Items.Insert(0, new ListItem("--选择区域--"));
}