TreeView动态绑定数据库(sql server 2000)

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);         }          }    }}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值