ASP.NET環境下完整的treeview使用類

來源:互聯網
上載者:User

#region 聲明
//----------------------------------------------------------------------
//
// 作者: 李淼(Nick.Lee)
//
// ASP.NET環境下完整的treeview控制項使用方式情節類
//
// 時間:2005-2-17
// boyorgril@msn.com
// QQ:16503096
//
//----------------------------------------------------------------------
#endregion
using System;
#region 自訂命名空間(可重用)
//調用本身函數引用命名空間
using NickLee.Web.UI;
using System.Data;
#endregion 

namespace NickLee.Web.UI
{
 /// <summary>
 /// menuFill 的摘要說明。
 /// </summary>
 public class menuFill
 {

  #region 類公用屬性和私人屬性
  webDataFill topFill=new webDataFill();
  webDataFill secFill=new webDataFill();
  webDataFill thirdFill=new webDataFill();

  private  string topMenu;
  private  string secMenu;
  private  string thirdMenu;
  #endregion

  #region 設定屬性條件參數

  /// <summary>
  /// 一級菜單sql語句,例:“select * from baseData_topMenu order by topMenu_Pk;”
  /// </summary>
  public  string sqltopMenuString
  {
   get{  return topMenu;}
   set{  topMenu=value;}
  }

  /// <summary>
  /// 二級菜單sql語句,例:“select * from baseData_secMenu where topMenu_PK=”
  /// </summary>
  public  string sqlsecMenuString
  {
   get{  return secMenu; }
   set{  secMenu=value; }
  }

  /// <summary>
  /// 三級菜單sql語句,例:“select * from baseData_thirdMenu where secMenu_PK=”
  /// </summary>
  public  string sqlthirdMenuString
  {
   get{  return thirdMenu; }
   set{  thirdMenu=value; }
  }

  #endregion

  public menuFill()
  {
   //
   // TODO: 在此處添加建構函式邏輯
   //
   #region 建構函式初始定義

   topFill.ConString=System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"];
   secFill.ConString=System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"];
   thirdFill.ConString=System.Configuration.ConfigurationSettings.AppSettings["SqlConnectionString"];

   topFill.dataTableName="topFill";
   secFill.dataTableName="secFill";
   thirdFill.dataTableName="thirdFill";
   #endregion
  }

  #region treeview分級顯示,用datareader
  /*
   * 
   * private void treeviewReader()
  {
   webDataFill fil1=new webDataFill();
   webDataFill fil2=new webDataFill();
   webDataFill fil3=new webDataFill();
   fil1.ConString="server=localhost;uid=sa;pwd=sa;database=northwind;";
   fil2.ConString="server=localhost;uid=sa;pwd=sa;database=northwind;";
   fil3.ConString="server=localhost;uid=sa;pwd=sa;database=northwind;";

   fil1.sqlQueryString="SELECT CategoryID, CategoryName FROM Categories";
   fil1.sqlClientDataReader();

   while(fil1.mySqlReader.Read())
   {
    Microsoft.Web.UI.WebControls.TreeNode  topNode=new Microsoft.Web.UI.WebControls.TreeNode();
    topNode.ID=fil1.mySqlReader["CategoryID"].ToString();
    topNode.Text=fil1.mySqlReader["CategoryName"].ToString();
    TreeView1.Nodes.Add(topNode);

    fil2.sqlQueryString = "SELECT ProductID, ProductName FROM Products where categoryID="+Convert.ToInt32(fil1.mySqlReader["CategoryID"]); 
    fil2.sqlClientDataReader();
    while(fil2.mySqlReader.Read())
    {
     Microsoft.Web.UI.WebControls.TreeNode   nextNode=new Microsoft.Web.UI.WebControls.TreeNode();
     nextNode.Text=fil2.mySqlReader["ProductName"].ToString();
     topNode.Nodes.Add(nextNode);

     fil3.sqlQueryString = "SELECT ProductID, ProductName FROM Products where ProductID<5"; 
     fil3.sqlClientDataReader();
     while(fil3.mySqlReader.Read())
     {
      Microsoft.Web.UI.WebControls.TreeNode   thirdNode=new Microsoft.Web.UI.WebControls.TreeNode();
      thirdNode.Text=fil3.mySqlReader["ProductID"].ToString();
      thirdNode.CheckBox=true;
      // thirdNode.NavigateUrl=fil3.mySqlReader["ProductID"].ToString();
      nextNode.Nodes.Add(thirdNode);
     }
     fil3.mySqlReader.Close();
     fil3.mySqlConnection.Close();
    }
    fil2.mySqlReader.Close();
    fil2.mySqlConnection.Close();
   
   }
   fil1.mySqlReader.Close();
   fil1.mySqlConnection.Close();

  }
  */
  
  #endregion

 }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.