代码:


TreeView(递归)(转)_xml<html xmlns="http://www.w3.org/1999/xhtml" >

TreeView(递归)(转)_xml<head runat="server">

TreeView(递归)(转)_xml    <title>无标题页</title>

TreeView(递归)(转)_xml</head>

TreeView(递归)(转)_xml<body>

TreeView(递归)(转)_xml    <form id="form1" runat="server">

TreeView(递归)(转)_xml        <div style="text-align:center;">

TreeView(递归)(转)_xml            <div style="margin:5px; float:left;"><asp:TreeView runat="server" ID="Tree1"></asp:TreeView></div>

TreeView(递归)(转)_xml            <div style="margin-left:12px;"><asp:GridView runat="server" ID="GridView1"></asp:GridView></div>

TreeView(递归)(转)_xml        </div> 

TreeView(递归)(转)_xml    </form>

TreeView(递归)(转)_xml</body>

TreeView(递归)(转)_xml</html>


 


public partial class InfoSort : System.Web.UI.Page

TreeView(递归)(转)_sql_14    {

TreeView(递归)(转)_sql_15        DataSet ds = null;

TreeView(递归)(转)_sql_15        protected void Page_Load(object sender, EventArgs e)

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            if (!IsPostBack)

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                BindData();

TreeView(递归)(转)_sql_15                loadtree();

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_sql_15        private void loadtree()

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            Tree1.Nodes.Clear();

TreeView(递归)(转)_sql_15            ds = GetDataSet("SELECT * FROM sort");

TreeView(递归)(转)_sql_15            InitTree(Tree1.Nodes, 0);

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_sql_15        private void InitTree(TreeNodeCollection Nds,int parentid)

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            DataView dv = new DataView();

TreeView(递归)(转)_sql_15            TreeNode tmpNd = null;

TreeView(递归)(转)_sql_15            dv.Table = ds.Tables[0];

TreeView(递归)(转)_sql_15            dv.RowFilter = String.Format("parentid={0}", parentid);

TreeView(递归)(转)_sql_15            foreach (DataRowView drv in dv)

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                tmpNd = new TreeNode();

TreeView(递归)(转)_sql_15                tmpNd.Text = (string)drv["sortname"];//节点名称

TreeView(递归)(转)_sql_15                tmpNd.NavigateUrl = String.Format("?id={0}", drv["id"]);//节点URL

TreeView(递归)(转)_sql_15                //tmpNd.ImageUrl = ""; //节点图片

TreeView(递归)(转)_sql_15                if (parentid == 0)

TreeView(递归)(转)_sql_15                    tmpNd.Expanded = true;

TreeView(递归)(转)_sql_15                else

TreeView(递归)(转)_sql_15                    tmpNd.Expanded = false;

TreeView(递归)(转)_sql_15                Nds.Add(tmpNd);

TreeView(递归)(转)_sql_15                InitTree(Nds[Nds.Count - 1].ChildNodes, (int)drv["id"]);

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_sql_15        private void BindData()

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            GridView1.DataSource = GetDataSet("select * from sort");

TreeView(递归)(转)_sql_15            GridView1.DataBind();

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_sql_15

TreeView(递归)(转)_xml_17        #region Dal

TreeView(递归)(转)_sql_15        private OleDbConnection GetConn

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            get

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                string path = Server.MapPath("App_Data/Database2.mdb");

TreeView(递归)(转)_sql_15                string _connStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", path);

TreeView(递归)(转)_sql_15                return new OleDbConnection(_connStr);

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_sql_15        private DataSet GetDataSet(string sql)

TreeView(递归)(转)_xml_17        {

TreeView(递归)(转)_sql_15            OleDbConnection _conn = null;

TreeView(递归)(转)_sql_15            OleDbDataAdapter odda = null;

TreeView(递归)(转)_sql_15            DataSet ds = null;

TreeView(递归)(转)_sql_15            try

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                ds = new DataSet();

TreeView(递归)(转)_sql_15                _conn = GetConn;

TreeView(递归)(转)_sql_15                _conn.Open();

TreeView(递归)(转)_sql_15                odda = new OleDbDataAdapter(sql, GetConn);

TreeView(递归)(转)_sql_15                odda.Fill(ds);

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_sql_15            catch (Exception ex)

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                throw new Exception(ex.Message);

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_sql_15            finally

TreeView(递归)(转)_xml_17            {

TreeView(递归)(转)_sql_15                if (odda != null)

TreeView(递归)(转)_sql_15                    odda.Dispose();

TreeView(递归)(转)_sql_15                if (_conn != null)

TreeView(递归)(转)_xml_17                {

TreeView(递归)(转)_sql_15                    _conn.Close();

TreeView(递归)(转)_sql_15                    _conn.Dispose();

TreeView(递归)(转)_xml_22                }

TreeView(递归)(转)_xml_22            }

TreeView(递归)(转)_sql_15            return ds;

TreeView(递归)(转)_xml_22        }

TreeView(递归)(转)_xml_22        #endregion

TreeView(递归)(转)_microsoft_96    }