下拉列表无级数据绑定

 

private string toadd = "├".

private void GetArticleCategory(string pid) { SqlConnection conn = new SqlConnection("server=.;database=test;uid=sa;pwd=;"); string sql = "select Articlesgroup_id,Groupname from Articlesgroup where Articlesgroup_parent_id=@pid order by Groupname"; SqlCommand cmd = new SqlCommand(sql, conn); SqlParameter Pid = new SqlParameter("@pid", SqlDbType.Int); Pid.Value = pid; cmd.Parameters.Add(Pid); conn.Open(); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { this.DropDownList1.Items.Add(new ListItem(toadd + " " + sdr[1].ToString(), sdr[0].ToString())); toadd += "─┴"; this.GetArticleCategory(sdr[0].ToString()); toadd = toadd.Substring(0, toadd.Length - 2); } sdr.Close(); conn.Close(); }

在Page_Load里调用

 

程序代码 程序代码


   protected void Page_Load(object sender, EventArgs e)

     {

         this.keyword.Attributes.Add("onfocus","if( this.value=='key key key') {this.value='' };");

         if (!Page.IsPostBack)

         {

             this.GetArticleCategory("0");

         }

         this.DropDownList1.Items.Insert(0, new ListItem("Search All", "all"));

     }



 

posted @ 2010-10-19 16:19  王长喜  阅读(257)  评论(0编辑  收藏  举报