//{ //绑定父dListParent // BindParent(); //} //获得传递过来的parent_id值,如果是第一次请求他为null string str = Request.QueryString["parent_id"]; string str1 = dListParent.SelectedValue;; Response.Write(str1); //如果str加个字符串!=原来的字符串则说明触发过dListParent的onchange事件 if((str+"abc")!="abc") { //绑定 dListChild控件 BindChild(str);//把传来的父DropDownList的value做为参数 } else BindParent(str1); }
protected void BindParent(string str) { //如果是第一次请求或者是刷新这个页面则根据dListParent的值来选择 //把参数转化成int int i = Convert.ToInt32(str); dListChild.Items.Clear(); dListChild.Items.Add(new ListItem("全部型号","0")); //得到数据库连接字符串 string connStr = ConfigurationSettings.AppSettings["ConnString"].ToString(); //初始化个conn对象 SqlConnection conn = new SqlConnection(connStr); //数据库语句 string commStr = string.Format("select type_value,type_text from phone_type where parent_id={0}",i); //建立数据库命令对象 SqlCommand comm = new SqlCommand(commStr,conn); //打开数据库 conn.Open(); //执行命令 SqlDataReader dr = comm.ExecuteReader(); //循环dr,给dListParent添加条目 while(dr.Read()) { dListChild.Items.Add(new ListItem(dr[1].ToString(),dr[0].ToString())); //也可以这样 //dListParent.Items.Add(new ListItem(dr["phone_text"].ToString(),dr["phone_value"].ToString())); } dListParent.Items[0].Selected = true; //添加下面这话的意思是当点提交按钮提交窗体的时候第二个dListChild的状态能够得到保存 dListChild.SelectedValue = Request.Form["dListChild"]; dr.Close(); conn.Close(); }
protected void BindChild(string str) { //通过js给包括dropdownlist任何控件添加的内容不会被保存状态 //把参数转化成int int i = Convert.ToInt32(str); //定义个字符串用保存从数据库返回的数据 string result = ""; //先清空输出的东西 Response.Clear();
上一篇:PHP与SQL注入攻击[二]
下一篇:有关在Windows下配置PHP+Apache+Optimizer失败的问题解决方案
|