Chinaunix首页 | 论坛 | 博客
  • 博客访问: 72254
  • 博文数量: 42
  • 博客积分: 2025
  • 博客等级: 大尉
  • 技术积分: 437
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-03 12:17
文章分类

全部博文(42)

文章存档

2010年(12)

2009年(30)

我的朋友

分类:

2009-11-29 18:24:59

添加一TreeView软件

<asp:TreeView ID="tvMenu" runat="server" ShowLines="True" ExpandDepth="0" Target="middle" Height="295px" OnLoad="tvMenu_Load" width="145px" BorderStyle="None" CollapseImageUrl="~/images/icon/folder.gif" ExpandImageUrl="~/images/icon/folderopen.gif" NoExpandImageUrl="~/images/icon/folder.gif" LineImagesFolder="~/TreeLineImages">

            <ParentNodeStyle Font-Bold="False" ForeColor="Black" ImageUrl="../images/icon/folder.gif" />

            <HoverNodeStyle Font-Underline="True" ForeColor="Blue" />

            <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" ForeColor="Green" ImageUrl="~/images/icon/folder.gif" />

            <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="DarkBlue" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="0px" />

        asp:TreeView>

 

 

OnLoad="tvMenu_Load",即先运动tvMenu_Load事件

protected void tvMenu_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            tvMenu.Dispose();

            myco = new MySqlConnection(strconn);

            myco.Open();

            this.createDataSet();

            myco.Close();

            this.InitTree(tvMenu.Nodes, "0");

        }

    }

protected void InitTree(TreeNodeCollection Nds, string idmde) //用递归方法动态生成节点

    {

        DataView dv = new DataView();

        TreeNode tmpNode;

        dv.Table = ds.Tables["Tree"];

        dv.RowFilter = "idmde=" + "'" + idmde + "'";

        foreach (DataRowView drv in dv)

        {

            tmpNode = new TreeNode();

            tmpNode.Value = drv["idmke"].ToString();

            tmpNode.Text = drv["denam"].ToString();

            tmpNode.NavigateUrl = drv["url"].ToString();

            tmpNode.ImageUrl = "../images/icon/sms_type11.gif";

            Nds.Add(tmpNode);

            this.InitTree(tmpNode.ChildNodes, tmpNode.Value);

        }

}

 

private DataSet createDataSet()

    {

        ds = new DataSet();

        string sqlstr = "select * from tree_depart";

        MySqlDataAdapter cmdSelect = new MySqlDataAdapter(sqlstr, myco);

        cmdSelect.Fill(ds, "Tree");

 

        //cmdSelect.Dispose();

        //sqlstr = "select * from kepart";

        //cmdSelect = new MySqlDataAdapter(sqlstr, myco);

        //cmdSelect.Fill(ds, "kepart");

 

        //cmdSelect.Dispose();

        //sqlstr = "select * from zupart";

        //cmdSelect = new MySqlDataAdapter(sqlstr, myco);

        //cmdSelect.Fill(ds, "zupart");

 

        return ds;

    }

 

private MySqlCommand mycomm;

    private MySqlDataReader dr;

    private string strconn = ConfigurationManager.AppSettings["Mysqlstudb"];

    private MySqlConnection myco;

DataSet ds;

 

阅读(376) | 评论(0) | 转发(0) |
0

上一篇:分布存储过程

下一篇:abap基础

给主人留下些什么吧!~~