首页 > 开发 > 综合 > 正文

在C#代码里使用IE WEB Control TreeView

2024-07-21 02:26:48
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 网站目录下需要有microsoft.web.ui.webcontrols.dll和相应的文件
    如大家要转载,请保留本人的版权。

    /*
    *description:完全的操作xml文件
    *auther:mingziweb_天很蓝
    *email:[email protected]
    *dates:22004-09-10
    *copyright:chongchong2008 yichang hubei china
    */



    .aspx
    <%@ register tagprefix="ie" namespace="microsoft.web.ui.webcontrols" assembly="microsoft.web.ui.webcontrols" %>
    <%@ page language="c#" codebehind="treeview.aspx.cs" autoeventwireup="false" inherits="test.webform1" %>
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
    <html>
    <head>
    <title>webform1</title>
    <meta name="generator" content="microsoft visual studio .net 7.1">
    <meta name="code_language" content="c#">
    <meta name="vs_defaultclientscript" content="javascript">
    <meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body ms_positioning="gridlayout">
    <form id="form1" method="post" runat="server">
    <font face="宋体">
    <ie:treeview id="mytreeview"
    runat="server"></ie:treeview></font>
    </form>
    </body>
    </html>



    .cs
    using system;
    using system.collections;
    using system.componentmodel;
    using system.data;
    using system.drawing;
    using system.web;
    using system.web.sessionstate;
    using system.web.ui;
    using system.web.ui.webcontrols;
    using system.web.ui.htmlcontrols;

    using system.data.sqlclient;
    using system.configuration;

    using microsoft.web.ui.webcontrols;

    namespace test
    {
    /// <summary>
    /// webform1 的摘要说明。
    /// </summary>
    public class webform1 : system.web.ui.page
    {
    protected microsoft.web.ui.webcontrols.treeview mytreeview;

    private sqlconnection myconnection = new sqlconnection(configurationsettings.appsettings["strconn"]);



    #region web 窗体设计器生成的代码
    override protected void oninit(eventargs e)
    {
    //
    // codegen: 该调用是 asp.net web 窗体设计器所必需的。
    //
    initializecomponent();
    base.oninit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void initializecomponent()
    {
    this.load += new system.eventhandler(this.page_load);

    }
    #endregion





    private void page_load(object sender, system.eventargs e)
    {
    // 在此处放置用户代码以初始化页面

    treenode mytreenoderoot = addtreenoderoot();
    appendchild(mytreenoderoot);

    }





    private treenode addtreenoderoot()
    {

    treenode mytreenode = new treenode();

    mytreenode.id = "420000";
    mytreenode.expanded = true;
    mytreenode.target = "";
    mytreenode.text = "我的社区";

    mytreeview.nodes.add(mytreenode);
    return mytreenode;
    }



    private treenode addsubnode(treenode subtreenode)
    {

    treenode mytreenode = new treenode();

    mytreenode.id = "00001";
    mytreenode.expanded = true;
    mytreenode.target = "";
    mytreenode.text = "省份";
    mytreenode.navigateurl = "" ;

    subtreenode.nodes.add(mytreenode);
    return mytreenode;
    }





    private void appendchild(treenode mytreenode)
    {

    treenode mysubnode = addsubnode(mytreenode);

    if(getclasstable().rows.count>0)
    {
    datatable mydatatable = new datatable();
    mydatatable = getclasstable();

    for(int i=0;i<mydatatable.rows.count;i++)
    {
    treenode mytreenodesub = new treenode();

    mytreenodesub.checkbox=true;
    if(i==20)
    {
    mytreenodesub.checked=true;

    }

    mytreenodesub.id = mydatatable.rows[i]["class_code"].tostring();
    mytreenodesub.expanded = false;
    mytreenodesub.target = "body";
    mytreenodesub.text = mydatatable.rows[i]["class_name"].tostring();
    mytreenodesub.navigateurl = "doclist.aspx?doccatalogguid=" + mydatatable.rows[i]["class_code"].tostring();

    mysubnode.nodes.add(mytreenodesub);

    appendchildren(mytreenodesub);

    }
    }
    }




    private void appendchildren(treenode mytreenode)
    {
    if(getsubclasstable(mytreenode.id).rows.count>0)
    {
    datatable mydatatable = new datatable();
    mydatatable = getsubclasstable(mytreenode.id);

    for(int i=0;i<mydatatable.rows.count;i++)
    {
    treenode mytreenodesub = new treenode();

    mytreenodesub.checkbox=true;


    mytreenodesub.id = mydatatable.rows[i]["subclass_code"].tostring();
    mytreenodesub.expanded = false;
    mytreenodesub.target = "body";
    mytreenodesub.text = mydatatable.rows[i]["subclass_name"].tostring();
    mytreenodesub.navigateurl = "doclist.aspx?doccatalogguid=" + mydatatable.rows[i]["class_code"].tostring();

    mytreenode.nodes.add(mytreenodesub);

    appendchildren(mytreenodesub);

    }
    }
    }





    private datatable getclasstable()
    {
    //绑定drpmc_code

    string strsql="select * from [class] order by id desc";

    openconnection();

    sqldataadapter mycommand = new sqldataadapter(strsql,myconnection);
    dataset ds= new dataset();
    mycommand.fill(ds);

    closeconnection();

    return ds.tables[0];

    }




    private datatable getsubclasstable(string class_code)
    {
    //绑定drpmc_code

    string strsql="select * from [subclass] where [email protected]_code order by id desc";

    openconnection();


    sqldataadapter mycommand = new sqldataadapter(strsql,myconnection);

    mycommand.selectcommand.commandtype=commandtype.text;
    mycommand.selectcommand.parameters.add("@class_code",sqldbtype.nvarchar,10).value=class_code
    ;
    dataset ds= new dataset();
    mycommand.fill(ds);

    closeconnection();

    return ds.tables[0];

    }




    /// <summary>
    /// 打开数据库连接
    /// </summary>

    private void openconnection()
    {

    if (myconnection.state == connectionstate.closed)
    myconnection.open();

    }





    /// <summary>
    /// 关闭数据库连接
    /// </summary>

    private void closeconnection()
    {

    if (myconnection.state == connectionstate.open)
    myconnection.close();

    }







    }
    }
    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表