麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

asp.net使用DataGridTree實現下拉樹的方法

2024-07-10 13:28:24
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了asp.net使用DataGridTree實現下拉樹的方法,詳細的講述了DataGridTree實現下拉樹的原理與具體實現方法,具有一定的參考借鑒價值,需要的朋友可以參考下
 
 

本文實例講述了asp.net使用DataGridTree實現下拉樹的方法。分享給大家供大家參考。具體實現方法如下:

下拉樹實現原理:輸出json到客戶端,客戶端實現動態加載,中間不會和服務端交互。數據量支持上經測試幾千還是很快的。本下拉樹控件是用c#+js樹實現。

2.c# 計算器 計算字符串數學表達式源碼

計算數學表達式原理 采用c#實現 很實用
//a.建立兩個棧:第一個位操作數棧,第二個操作符符棧!(將棧定義為string類型)
//b.對數字來說是無條件壓入數字棧中.
//c.而對符號來說,只有當前棧頂元素的優先值小于掃到的符號時(比如”+”小于”*”),此符號才壓入棧;否則大于等于的情況是將當前棧頂元素彈出棧,與當前數字棧的前兩個數字組成式子進行計算.計算結果當作數字壓入數字棧作為棧頂元素(要舍棄已經彈出的兩個數字),而那個掃描到的符號則將代替那個彈出的符號作為棧頂元素)。
//d.最后說一下括號,原則是掃描到左括號時無條件壓入符號棧,而掃到右括號時,則彈出離棧頂最近的一個左括號以上的全部符號與數字棧的數字做運算

3.asp.net教程 datagridtree表格樹控件 

繼承asp.net的datagrid控件實現的表格樹控件
/*表格樹控件說明 
* 此控件繼承datagrid 新增屬性說明:
* 1.treeparentcode:頂級根節點parentcode
* 2.treedisplaydeep:展現表格樹深度默認為1 
* 3.sumcolumns:自動匯總到根節點的字段集合 針對 decimal類型
* 4.新增樹狀列模板templatetreecolumn 此模板繼承了templatecolumn 重寫了方法initializecell 
* 客戶端新增特性配置說明 
* 1.固定列 配置 itemstyle-css教程class='tdlockedclass' 
* 2.固定表頭 配置 headerstyle-cssclass='trlockedclass'
* 3.文本框 input 或 <asp:textbox 配置事件onchange='sumparent(this);' 數字改變相應所有父節點也隨著改變 針對數字型 其他不支持 
* 不過可以自定義js
* 報表說明:
* 1.datagridtree.enableviewstate=false;提高加載速度
* 2.動態定義列 實現 boundcolumn column = new boundcolumn();
column.headertext = "動態列";
column.datafield = "unitname";
datagridnew.columns.add(column);
* 也可以自定義默認模板 動態加載模板 定義模板例子templatetreecolumn,不用繼承templatecolumn,實現接口 itemplate initializecell 方法就可以了
* 不足之處:1.對于復雜多行表頭 不知 如何實現
* 2.表頭和列固定 數據量大時 會影響反映速度 一千左右的數據量 還時沒問題的 數據量在大的話 課考慮采用ajax動態加載 目前此功能還沒實現
實例代碼

復制代碼代碼如下:
private void maketree(datatable dtnodesets, string strparentcolumn, string strrootvalue, string strindexcolumn, string strtextcolumn, dropdownlist drpbind, int i)
{
//每向下一層,多一個縮入單位   
i++;
dataview dvnodesets = new dataview(dtnodesets);
dvnodesets.rowfilter = strparentcolumn + "=" + strrootvalue;
string strpading = ""; //縮入字符  
//通過i來控制縮入字符的長度,我這里設定的是一個全角的空格   
for (int j = 0; j < i; j++)
strpading += " ";//如果要增加縮入的長度,改成兩個全角的空格就可以了  
foreach (datarowview drv in dvnodesets)
{
treenode tnnode = new treenode();
listitem li = new listitem(strpading + "├" + drv[strtextcolumn].tostring(), drv[strindexcolumn].tostring());
drpbind.items.add(li);
maketree(dtnodesets, strparentcolumn, drv[strindexcolumn].tostring(), strindexcolumn, strtextcolumn, drpbind, i);
}
//遞歸結束,要回到上一層,所以縮入量減少一個單位   
i--;
}
/// <summary>   
/// sql語句查詢,再綁定到droplist里面   
/// </summary>   
private void createtree()
{
//查詢zonelist   
string sql = "select * from master_department where parent_department='003'";
dataset ds = db.getds();
datatable dt = ds.tables[0];
maketree(dt, "parent_department", "003", "department_code", "department_name", dropdownlist1, -1);
}

網上找的另一個比較好的實例
復制代碼代碼如下:
using system;
using system.collections.generic;
using system.text;
using system.web.ui.webcontrols;
namespace interface.common
{
    public interface idropdowntree : idisposable
    {
        /**//// <summary>
        /// 返回dictionary里分別對應id,文本,如果沒有子節點返回null
        /// </summary>
        /// <param name="parentid">父節點id</param>
        /// <returns></returns>
        dictionary<string, string> getchildcategory(string parentid);
        /**//// <summary>
        /// 代碼里寫return new interface.common.dropdowntree(this);
        /// </summary>
        dropdowntree dropdowntree
        {
            get;
        }
    }
    public sealed class dropdowntree
    {
        idropdowntree _dropdowntree;
        public dropdowntree(idropdowntree dropdowntree)
        {
            _dropdowntree = dropdowntree;
        }
        /**//// <summary>
        /// 用于樹的前綴
        /// </summary>
        /// <param name="islast">是否是同級節點中的最后一個</param>
        /// <param name="haschild">本節點是否擁有子節點</param>
        /// <param name="parentstring">父節點前綴符號</param>
        /// <returns>本節點的前綴</returns>
        private string getprefix(bool islast, bool haschild, string parentstring)
        {
            string result = string.empty;
            if (!string.isnullorempty(parentstring))
            {
                parentstring = parentstring.remove(parentstring.length - 1).replace("├", "│").replace("└", " ");
                result += parentstring;
            }
            if (islast)
            {
                result += "└";
            }
            else
            {
                result += "├";
            }
            if (haschild)
            {
                result += "┬";
            }
            else
            {
                result += "─";
            }
            return result;
        }
        綁定下拉菜單#region 綁定下拉菜單
        /**//// <summary>
        /// 綁定連動級的下拉菜單
        /// </summary>
        /// <param name="ddlgoodstype">傳進一個被綁定的dropdownlist</param>
        /// <param name="removeid">被排除綁定的節點id</param>
        /// <param name="autodispose">是否自動釋放</param>
        public void bindtodropdownlist(dropdownlist ddlgoodstype, string removeid,string parentid, bool autodispose)
        {
            if (ddlgoodstype != null)
            {
                listitem listitem = null;
                string currentid = parentid;//根節點/父id
                string currentsign = string.empty;//當前節點符號;
                string parrentsign = string.empty; //父節點符號;
                bool haschild = true;//是否有子
                queue<string> parentkeylist = new queue<string>();//存 有子節點的 節點id
                queue<string> parentsignlist = new queue<string>();//對應節點id的前綴符號
                int itemindexof = 0;//父節點所在的位置 
                while (haschild)
                {
                    int lastonecount = 1;//用于計算在同級別中是否最后一個
                    dictionary<string, string> childlist = _dropdowntree.getchildcategory(currentid);// 得到子節點列表
                    if (childlist != null && childlist.count > 0)
                    {
                        if (!string.isnullorempty(removeid) && childlist.containskey(removeid))
                        {
                            childlist.remove(removeid);
                        }
                        foreach (keyvaluepair<string, string> entry in childlist)
                        {
                            if (_dropdowntree.getchildcategory(entry.key) != null)//存在子
                            {
                                currentsign = getprefix(lastonecount == childlist.count, true, parrentsign);
                                listitem = new listitem(currentsign + entry.value, entry.key);
                                parentkeylist.enqueue(entry.key);//當前的節點id
                                parentsignlist.enqueue(currentsign);//當前的節點符號
                            }
                            else//不存在子
                            {
                                currentsign = getprefix(lastonecount == childlist.count, false, parrentsign);
                                listitem = new listitem(currentsign + entry.value, entry.key);
                            }
                            if (ddlgoodstype.items.count != 0)
                            {
                                itemindexof = string.isnullorempty(currentid) ? itemindexof + 1 : ddlgoodstype.items.indexof(ddlgoodstype.items.findbyvalue(currentid)) + lastonecount;
                            }
                            ddlgoodstype.items.insert(itemindexof, listitem);//添加子節點
                            lastonecount++;
                        }
                        if (parentkeylist.count > 0)//存在子節點時
                        {
                            currentid = parentkeylist.dequeue();
                            parrentsign = parentsignlist.dequeue();
                        }
                        else
                        {
                            haschild = false;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                if (autodispose)
                {
                    _dropdowntree.dispose();
                }
            }
        }
        /**//// <summary>
        /// 綁定連動級的下拉菜單
        /// </summary>
        /// <param name="ddlgoodstype">傳進一個被綁定的dropdownlist</param>
        public void bindtodropdownlist(dropdownlist ddlgoodstype)
        {
            bindtodropdownlist(ddlgoodstype, string.empty,null, true);
        }
        /**//// <summary>
        /// 綁定連動級的下拉菜單
        /// </summary>
        /// <param name="ddlgoodstype">傳進一個被綁定的dropdownlist</param>
        /// <param name="removeid">被排除的id</param>
        public void bindtodropdownlist(dropdownlist ddlgoodstype, string removeid)
        {
            bindtodropdownlist(ddlgoodstype, removeid,null, true);
        }
        /**//// <summary>
        /// 綁定連動級的下拉菜單
        /// </summary>
        /// <param name="ddlgoodstype">傳進一個被綁定的dropdownlist</param>
        /// <param name="removeid">被排除的id,若沒有,傳null</param>
        /// <param name="parentid">起始父id</param>
        public void bindtodropdownlist(dropdownlist ddlgoodstype, string removeid,string parentid)
        {
            bindtodropdownlist(ddlgoodstype, removeid,parentid, true);
        }
        #endregion
    }
}

調用方法很簡單: 
1.繼承自idropdowntree接口
2.實現3個接口方法實現接口代碼示例[dispose方法自己實現],最主要的是自己實現獲得子級的方法
復制代碼代碼如下:
idropdowntree 成員
#region idropdowntree 成員
public dictionary<string, string> getchildcategory(string parentid)
{
    string where = "parentid='" + parentid + "'";
    if (string.isnullorempty(parentid))
    {
 where = "parentid is null or parentid='" + guid.empty + "'";
    }
    list<goodscategorybean> _goodscategorylist = selectlist(0, where, string.empty, false);
    if (_goodscategorylist != null && _goodscategorylist.count > 0)
    {
 dictionary<string, string> categorylist = new dictionary<string, string>();
 for (int i = 0; i < _goodscategorylist.count; i++)
 {
     categorylist.add(_goodscategorylist[i].id.tostring(), _goodscategorylist[i].gategoryname);
 }
 return categorylist;
    }//51aspx.com
    return null;
}
public interface.common.dropdowntree dropdowntree
{
    get { return new interface.common.dropdowntree(this); }
}
#endregion

頁面調用代碼: 類名.dropdowntree.bindtodropdownlist(下拉控件id);

 

希望本文所述對大家的asp.net程序設計有所幫助。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品视频在线观看免费 | 成人激情综合网 | 欧美成人影院 | 国产高清自拍一区 | 亚洲精品一区二区三区免 | 成人在线视频播放 | 欧美日韩在线播放一区 | 国产精品99一区二区 | 毛片一级片 | 成人做爰高潮片免费视频韩国 | 久久久久久中文字幕 | 亚洲午夜一区二区三区 | 538任你躁在线精品视频网站 | 女18一级大黄毛片免费女人 | 嗯~啊~用力~高h | 99爱视频在线观看 | 综合网天天色 | 在线亚洲欧美 | 国产精品久久久乱弄 | 激情小说另类 | 黄色一级片免费观看 | 亚洲精品一二三区 | 九九热视频在线免费观看 | 免费国产在线精品 | 久久精品欧美视频 | 成人短视频在线观看 | 国产成人精品免费视频大全办公室 | 久久久激情网 | 国产福利视频在线观看 | 亚洲视屏 | 国产美女爽到喷白浆的 | 国产精品久久久免费观看 | 一级毛片电影网 | 欧美一区在线观看视频 | 免费亚洲视频在线观看 | 羞羞视频免费视频欧美 | 91亚洲免费视频 | 久久久久久久久久久一区 | 91成人在线免费观看 | 国产午夜精品一区二区三区四区 | xxxx69hd一hd72|