回 帖 发 新 帖 刷新版面

主题:DropDownList二级联动的取值问题,急急急

用2个dropdownlist做省--市联动,想利用button取得子控件选择的城市名称,父控件已经设置了autopostback,而且也写了if   (!IsPostBack),可每次button提交后页面一刷新,子控件自动返回到第一项,所以每次取得的都是第一个城市的名字。怎么解决,或则大家有什么其他方法,   下面是我的代码: 
        protected   void   Page_Load(object   sender,   EventArgs   e) 
        { 
                if   (!IsPostBack) 
                { 
                        SetProvince(); 
                        SetCity(); 
                        
                }                 
        } 
        private   void   SetProvince()                               // 
        { 
                string   sql   =   "select   *   from   Department"; 
                DataSet   ds   =   new   DataSet(); 
                conn.Open(); 
                SqlDataAdapter   sda   =   new   SqlDataAdapter(sql,conn); 
                sda.Fill(ds); 
                ddlProvince.DataTextField   =   "DepartmentName"; 
                ddlProvince.DataValueField   =   "DepartmentID"; 
                ddlProvince.DataSource   =   ds; 
                ddlProvince.DataBind();                 
                conn.Close(); 
        } 
        private   void   SetCity() 
        { 
                string   sql   =   "select   *   from   EmployeeInfo     where   BusinessID   ='"   +   ddlProvince.SelectedValue   +   "'"; 
                DataSet   ds   =   new   DataSet(); 
                conn.Open(); 
                SqlDataAdapter   sda   =   new   SqlDataAdapter(sql,conn); 
                sda.Fill(ds); 
                ddlCity.DataTextField   =   "Name"; 
                ddlCity.DataValueField   =   "BusinessID"; 
                ddlCity.DataSource   =   ds; 
                ddlCity.DataBind(); 
                conn.Close(); 
        } 
        protected   void   ddlProvince_SelectedIndexChanged(object   sender,   EventArgs   e) 
        { 
                SetCity(); 
        } 

        protected   void   Button1_Click(object   sender,   EventArgs   e) 
        { 
                lblAddress.Text   =   ddlProvince.SelectedItem.Text   +   ddlCity.SelectedItem.Text;   

        }

回复列表 (共1个回复)

沙发


用hidden来保存值试一下,或者用Ajax来做。

我来回复

您尚未登录,请登录后再回复。点此登录或注册