• ASP.Net中省市级联有关


    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 }
  • 相关阅读:
    P3302 [SDOI2013]森林
    P2542 [AHOI2005] 航线规划
    P5795 [THUSC2015]异或运算
    P3320 [SDOI2015]寻宝游戏
    P1963 [NOI2009] 变换序列
    一月练习日志
    计算几何全家桶
    bzoj1076: [SCOI2008]奖励关(期望dp+状压dp)
    bzoj3450 Easy(概率期望dp)
    Eclipse配置 自动补全功能 快捷键 alt+/
  • 原文地址:https://www.cnblogs.com/wsl2011/p/2064117.html
Copyright © 2020-2023  润新知