文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>ASP.Net中省市级联有关

ASP.Net中省市级联有关

时间:2011-05-31  来源:笨笨的菜鸟

View Code
 1 public partial class City : System.Web.UI.Page
2 {
3 protected void Page_Load(object sender, EventArgs e)
4 {
5 if(!IsPostBack)
6 {
7 BindProv();
8 BindCity();
9 }
10 }
11
12 //绑定市
13 private void BindCity()
14 {
15 ddlcity.Items.Clear();
16 DataTable citydt = new CitySer().GetAllCityByProvId(int.Parse(ddlprov.SelectedValue.ToString()));
17 foreach (DataRow dr in citydt.Rows)
18 {
19 ddlcity.Items.Add(new ListItem(dr["cityName"].ToString(), dr["id"].ToString()));
20 }
21 }
22 //绑定省
23 private void BindProv()
24 {
25 ddlprov.Items.Clear();
26 DataTable dt = new CitySer().GetAllProv();
27 foreach(DataRow dr in dt.Rows)
28 {
29 ddlprov.Items.Add(new ListItem(dr["provinceName"].ToString(),dr["id"].ToString()));
30 }
31 }
32 //联动
33 protected void ddlprov_SelectedIndexChanged(object sender, EventArgs e)
34 {
35 if (ddlprov.Items.Count != 0)
36 {
37 ddlcity.Items.Clear();
38 DataTable citydt = new CitySer().GetAllCityByProvId(int.Parse(ddlprov.SelectedValue.ToString()));
39 foreach (DataRow dr in citydt.Rows)
40 {
41 ddlcity.Items.Add(new ListItem(dr["cityName"].ToString(), dr["id"].ToString()));
42 }
43 }
44 }
45 }
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载