遞歸生成新聞分類列表dropdownlist的項集合

           

           public void BindSortData()
                  {
                      DataTable dt = this.Db.GetTable("select Column_ID,Column_Name,Column_Depth from Expro_NewsType where Column_Depth=1");
                      SortList(dt,"0");
                  }
                  public void SortList(DataTable dt,string parentId)
                  {
                   
                      if (dt != null)
                      {
                          DataRow dr = null;
                          string tempColumnId = "";
                          string tempColumn_Name = "";
                          int tempColumn_Depth = 0;

                          if (dt.Rows.Count > 0)
                          {

                

                              for (int i = 0; i < dt.Rows.Count; i++)
                              {
                                  dr = dt.Rows[i];
                                  tempColumnId = Convert.ToString(dr["Column_ID"] ?? "");
                                  tempColumn_Name = Convert.ToString(dr["Column_Name"] ?? "");
                                  tempColumn_Depth = int.Parse(Convert.ToString(dr["Column_Depth"] ?? ""));

                                  DataTable dtTemp = this.Db.GetTable("select Column_ID,Column_Name,Column_Depth from Expro_NewsType where Parent_ID=@Parent_ID", new System.Data.SqlClient.SqlParameter("@Parent_ID", tempColumnId));
                                  if (dtTemp != null && dtTemp.Rows.Count>0)
                                  {
                                      string tempGe = "";
                                      for (int j = 0; j < tempColumn_Depth - 1; j++)
                                      {
                                          tempGe += "";
                                      }
                                      this.DdlGTypeId.Items.Add(new ListItem(tempGe + tempColumn_Name, tempColumnId));
                                      SortList(dtTemp, tempColumnId);
                                  }
                                  else
                                  {

                                      string tempGe = "";
                                      for (int j = 0; j < tempColumn_Depth-1; j++)
                                      {
                                          tempGe += "";
                                      }
                                      this.DdlGTypeId.Items.Add(new ListItem(tempGe+tempColumn_Name, tempColumnId));
                                  }


                              }
                          }
               
                      }
                     
                  }

          posted on 2009-03-13 15:12 sanmao 閱讀(204) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 南靖县| 连南| 祁门县| 昔阳县| 吉林市| 辽源市| 小金县| 天长市| 定西市| 丰县| 咸宁市| 红桥区| 贵州省| 塔河县| 东阿县| 泰和县| 贵港市| 南漳县| 醴陵市| 长汀县| 远安县| 额尔古纳市| 盖州市| 辽源市| 万源市| 辉县市| 突泉县| 武邑县| 罗定市| 凉城县| 宜章县| 金山区| 北碚区| 通山县| 金昌市| 龙井市| 民丰县| 临江市| 镇江市| 沂南县| 云安县|