using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient; public partial class _Default : System.Web.UI.Page { private static SqlConnection con; private SqlCommand com; private DataSet objdataset; private SqlDataAdapter objdataapter; protected void Page_Load(object sender, EventArgs e) { if (!(Page.IsPostBack)) getss(); } public SqlConnection GetConn() { con = new SqlConnection("server=.;uid=sa;pwd=sa;database=jb_crm_team0"); return con; } public void getss() { con = this.GetConn(); string sql = "select right_text,right_code from sys_right where right_type='Folder'"; objdataapter = new SqlDataAdapter(sql, con); objdataset = new DataSet(); objdataapter.Fill(objdataset, "jobs"); for (int i = 0; i < objdataset.Tables[0].Rows.Count; i++) { TreeNode dd = new TreeNode(); dd.Text = objdataset.Tables[0].Rows[i]["right_text"].ToString(); dd.Value = objdataset.Tables[0].Rows[i]["right_text"].ToString(); this.TreeView1.Nodes.Add(dd); string sql1 = "select right_text from sys_right where right_type='Document' and right_parent_code='"+objdataset.Tables[0].Rows[i]["right_code"].ToString()+"'"; con = this.GetConn(); con.Open(); com = new SqlCommand(sql1, con); SqlDataReader reader=com.ExecuteReader(); while (reader.Read()) { TreeNode dnn=new TreeNode(); dnn.Value=reader.GetValue(0).ToString(); dnn.Text=reader.GetValue(0).ToString(); this.TreeView1.Nodes[i].ChildNodes.Add(dnn); } } }}
TreeView动态绑定数据库(sql server 2000)
最新推荐文章于 2024-08-26 16:32:13 发布