AjaxPro.NET框架生成高效率的Tree(Asp.net 2.0)(示例代码下载)

本文介绍了一种利用AjaxPro.NET框架实现的高效树形菜单方案。该方案采用按需加载的方式,只在需要时通过Ajax请求加载指定节点的子项,有效减少了初始加载时间,并保持了良好的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(一). 说明
        用Tree显示菜单及物品列表(从服务端获取数据)比较方便, 当前显示Tree 主要有两种方式:
        1. 在Tree初始化时将数据全部一次性从服务端获取, 获取完数据后页面展开或收缩时就不再需要获取数据,这样, 获取完数据使用时效率比较高, 但当树节点很多时, 在每次初始化时会有较大的延迟.
        2. 初始化时只加载展开的节点, 当用户需要查看某个节点下的数据时, 再去取数据, 这样, 初始化时延迟会相对减少, 但每次单击节点时要获取数据, 页面每次都要刷新, 所以也会产生延迟.
        此事例用Ajax实现第二种方式, 每次只动态加载要展开的节点数据(闭合节点不展开时,则不获取其子节点的数据),  另外加载节点时页面不会刷新.

(二). 运行示例图
AjaxTree1.jpgAjaxTree2.jpg

(三). AjaxPro.NET简介

         首先对AjaxPro.NET作一下介绍, AjaxPro.NET是一个优秀的Ajax框架, 在实际应用中只要添加其DLL引用并进行简单的配置, 即可以非常方便的在客户端直接调用服务端方法, 来获取Tree节点.

(四).使用AjaxPro.NET预配置

       1. 添加 AjaxPro.dll 文件的引用(示例代码中已经包含,直接COPY过来使用即可).
       2. 在Web.config文件中添加以下配置.

None.gif < httpHandlers >
None.gif            
< add verb = " POST,GET "  path = " ajaxpro/*.ashx "  type = " AjaxPro.AjaxHandlerFactory, AjaxPro "   />
None.gif
</ httpHandlers >
None.gif

      3. 在要使用AjaxPro.NET框架的页面 *.aspx.cs 的 Page_Load事件中加如下代码:

None.gif AjaxPro.Utility.RegisterTypeForAjax( typeof (_Default));

      4. 经过以上三步骤后, 只要在后台服务端的方法前面增加属性[AjaxMethod]后:

None.gif    [AjaxMethod()]     //  or [AjaxPro.AjaxMethod] 
None.gif
   public  ArrayList GetSearchItems(  string  strQuery )
ExpandedBlockStart.gifContractedBlock.gif  
dot.gif {
InBlock.gif       
//生成数据源
InBlock.gif
       ArrayList items = new ArrayList();
InBlock.gif       items.Add(
"King");
InBlock.gif       items.Add(
"Rose");
InBlock.gif       
return items ;
ExpandedBlockEnd.gif  }
 
None.gif

         就可以在客户端直接使用服务端方法, 非常方便, 客户端调用后台代码如下:

None.gif var returnValue  =  后台代码类名.GetSearchItems(参数);

(五). 代码

         1. 页面 Tree.aspx 代码:

None.gif <% @ Page Language = " C# "  AutoEventWireup = " true "   CodeFile = " Tree.aspx.cs "  Inherits = " _Default "   %>
None.gif 
None.gif 
<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
None.gif 
None.gif 
< html xmlns = " http://www.w3.org/1999/xhtml "   >
None.gif 
< head runat = " server " >
None.gif     
< title > Ajax Efficient Tree </ title >
None.gif     
< link type = " text/css "  href = " css/tree.css "  rel = " stylesheet " >
None.gif 
</ head >
None.gif 
< body >
None.gif     
< form id = " form1 "  runat = " server " >
None.gif     
< div >
None.gif         
< asp:Panel ID = " Panel1 "  runat = " server "  Height = " 424px "  Width = " 251px " >
None.gif             
< div id = " CategoryTree "   class = " TreeMenu " ></ div >
None.gif         
</ asp:Panel >
None.gif         
< script language = " jscript " >
None.gif             var tree 
=  document.getElementById( " CategoryTree " );
None.gif             var root 
=  document.createElement( " li " );
None.gif             root.id 
=   " li_0 " ;
None.gif             tree.appendChild( root );
None.gif             ExpandSubCategory( 
0  );
None.gif             function ExpandSubCategory( categoryID )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {
InBlock.gif                 var liFather 
= document.getElementById( "li_" + categoryID );
InBlock.gif                 
if( liFather.getElementsByTagName("li").length > 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     ChangeStatus( categoryID );
InBlock.gif                     
return;
ExpandedSubBlockEnd.gif                 }

InBlock.gif                 liFather.className 
= "Opened";
InBlock.gif                 SwitchNode( categoryID, 
true );
InBlock.gif                 
InBlock.gif                 
//仅获取当前节点的子Nodes
InBlock.gif
                 _Default.GetSubCategory( categoryID, GetSubCategory_callback );
ExpandedBlockEnd.gif             }
            
None.gif             function SwitchNode( CategoryID, show )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {
InBlock.gif                 var li_father 
= document.getElementById("li_" + CategoryID);
InBlock.gif                 
if( show )
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     var ul 
= document.createElement("ul");
InBlock.gif                     ul.id 
= "ul_note_" + CategoryID;
InBlock.gif                     
InBlock.gif                     var note 
= document.createElement("li");
InBlock.gif                     note.className 
= "Child";              
InBlock.gif                     
InBlock.gif                     var img 
= document.createElement("img");
InBlock.gif                     img.className 
= "s";
InBlock.gif                     img.src 
= "css/s.gif";                    
InBlock.gif                     
InBlock.gif                     var a 
= document.createElement("a");
InBlock.gif                     a.href 
= "javascript:void(0);";
InBlock.gif                     a.innerHTML 
= "Please waiting";
InBlock.gif                     
InBlock.gif                     note.appendChild(img);
InBlock.gif                     note.appendChild(a);
InBlock.gif                     ul.appendChild(note);
InBlock.gif                     li_father.appendChild(ul);                                        
ExpandedSubBlockEnd.gif                 }
   
InBlock.gif                 
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     var ul 
= document.getElementById("ul_note_" + CategoryID );
InBlock.gif                     
if( ul )
ExpandedSubBlockStart.gifContractedSubBlock.gif                     
dot.gif{
InBlock.gif                         li_father.removeChild(ul);
ExpandedSubBlockEnd.gif                     }

ExpandedSubBlockEnd.gif                 }
             
ExpandedBlockEnd.gif             }

None.gif             function GetSubCategory_callback( response )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {
InBlock.gif                var dt 
= response.value.Tables[0];
InBlock.gif                
if( dt.Rows.length > 0 )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                     var iCategoryID 
= dt.Rows[0].FatherID;               
ExpandedSubBlockEnd.gif                }
                                
InBlock.gif                var li_father 
= document.getElementById("li_" + iCategoryID );
InBlock.gif                var ul 
= document.createElement("ul");
InBlock.gif                
for( var i = 0; i < dt.Rows.length; i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                     
if( dt.Rows[i].IsChild == 1 )
ExpandedSubBlockStart.gifContractedSubBlock.gif                     
dot.gif{
InBlock.gif                         var li 
= document.createElement("li");
InBlock.gif                         li.className 
= "Child";
InBlock.gif                         li.id 
= "li_" + dt.Rows[i].CategoryID;
InBlock.gif                         var img 
= document.createElement("img");
InBlock.gif                         img.id 
= dt.Rows[i].CategoryID;
InBlock.gif                         img.className 
= "s";
InBlock.gif                         img.src 
= "css/s.gif";
InBlock.gif                         var a 
= document.createElement("a");
InBlock.gif                         a.href 
= "javascript:OpenDocument('" + dt.Rows[i].CategoryID + "');";
InBlock.gif                         a.innerHTML 
= dt.Rows[i].CategoryName;                                          
ExpandedSubBlockEnd.gif                     }

InBlock.gif                     
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                     
dot.gif{
InBlock.gif                         var li 
= document.createElement("li");
InBlock.gif                         li.className 
= "Closed";
InBlock.gif                         li.id 
= "li_" + dt.Rows[i].CategoryID;
InBlock.gif                         var img 
= document.createElement("img");
InBlock.gif                         img.id 
= dt.Rows[i].CategoryID;
InBlock.gif                         img.className 
= "s";
InBlock.gif                         img.src 
= "css/s.gif";
ExpandedSubBlockStart.gifContractedSubBlock.gif                         img.onclick 
= function()dot.gif{ ExpandSubCategory( this.id ); };
InBlock.gif                         img.alt 
= "Expand/collapse";
InBlock.gif                         var a 
= document.createElement("a");
InBlock.gif                         a.href 
= "javascript:ExpandSubCategory('" + dt.Rows[i].CategoryID + "');";
InBlock.gif                         a.innerHTML 
= dt.Rows[i].CategoryName;                                         
ExpandedSubBlockEnd.gif                     }

InBlock.gif                     li.appendChild(img);
InBlock.gif                     li.appendChild(a);
InBlock.gif                     ul.appendChild(li);
ExpandedSubBlockEnd.gif                }

InBlock.gif                li_father.appendChild(ul);
InBlock.gif                SwitchNode( iCategoryID, 
false );
ExpandedBlockEnd.gif             }
          
None.gif             
None.gif             
// 单击叶节点时, 异步从服务端获取单个节点的数据.
None.gif
             function OpenDocument( CategoryID )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {                
InBlock.gif                 _Default.GetNameByCategoryID( CategoryID, GetNameByCategoryID_callback );
ExpandedBlockEnd.gif             }

None.gif             
None.gif             function GetNameByCategoryID_callback( response )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {
InBlock.gif                 alert( response.value );
ExpandedBlockEnd.gif             }

None.gif             
None.gif             function ChangeStatus( CategoryID )
ExpandedBlockStart.gifContractedBlock.gif             
dot.gif {
InBlock.gif                 var li_father 
= document.getElementById("li_" + CategoryID );
InBlock.gif                 
if( li_father.className == "Closed" )
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     li_father.className 
= "Opened";
ExpandedSubBlockEnd.gif                 }

InBlock.gif                 
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                 
dot.gif{
InBlock.gif                     li_father.className 
= "Closed";
ExpandedSubBlockEnd.gif                 }

ExpandedBlockEnd.gif            }
              
None.gif         
</ script >           
None.gif     
</ div >
None.gif     
</ form >     
None.gif 
</ body >       
None.gif 
</ html >
None.gif
None.gif

         2. 页面后台文件 Tree.aspx.cs 代码: 

None.gif using  System;
None.gif 
using  System.Data;
None.gif 
using  System.Configuration;
None.gif 
using  System.Web;
None.gif 
using  System.Web.Security;
None.gif 
using  System.Web.UI;
None.gif 
using  System.Web.UI.WebControls;
None.gif 
using  System.Web.UI.WebControls.WebParts;
None.gif 
using  System.Web.UI.HtmlControls;
None.gif 
None.gif 
public  partial  class  _Default : System.Web.UI.Page 
ExpandedBlockStart.gifContractedBlock.gif 
dot.gif {
InBlock.gif    
//此对象用于存放所有的节点数
InBlock.gif
    public static DataSet dsAllNodes = new DataSet();
InBlock.gif 
InBlock.gif    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        AjaxPro.Utility.RegisterTypeForAjax(
typeof(_Default));       
InBlock.gif        CreateNodes();
ExpandedSubBlockEnd.gif    }

InBlock.gif 
InBlock.gif    
private DataTable CreateStructure()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       DataTable dt 
= new DataTable();
InBlock.gif       dt.Columns.Add(
new DataColumn("CategoryID"typeof(int)));
InBlock.gif       dt.Columns.Add(
new DataColumn("CategoryName"typeof(string)));
InBlock.gif       dt.Columns.Add(
new DataColumn("FatherID"typeof(string)));
InBlock.gif       dt.Columns.Add(
new DataColumn("IsChild"typeof(bool)));
InBlock.gif       
return dt;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
public void CreateNodes()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       DataTable dt 
= this.CreateStructure();
InBlock.gif 
InBlock.gif       DataRow drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 1;
InBlock.gif       drNew[
"CategoryName"= "物品类别";
InBlock.gif       drNew[
"FatherID"= 0;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 2;
InBlock.gif       drNew[
"CategoryName"= "水果";
InBlock.gif       drNew[
"FatherID"= 1;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 3;
InBlock.gif       drNew[
"CategoryName"= "工具";
InBlock.gif       drNew[
"FatherID"= 1;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 4;
InBlock.gif       drNew[
"CategoryName"= "萍果";
InBlock.gif       drNew[
"FatherID"= 2;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 5;
InBlock.gif       drNew[
"CategoryName"= "香蕉";
InBlock.gif       drNew[
"FatherID"= 2;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 6;
InBlock.gif       drNew[
"CategoryName"= "桔子";
InBlock.gif       drNew[
"FatherID"= 2;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 7;
InBlock.gif       drNew[
"CategoryName"= "萝卜";
InBlock.gif       drNew[
"FatherID"= 2;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 8;
InBlock.gif       drNew[
"CategoryName"= "钢笔";
InBlock.gif       drNew[
"FatherID"= 3;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 9;
InBlock.gif       drNew[
"CategoryName"= "铅笔";
InBlock.gif       drNew[
"FatherID"= 3;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 10;
InBlock.gif       drNew[
"CategoryName"= "尺子";
InBlock.gif       drNew[
"FatherID"= 3;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif       
InBlock.gif       drNew 
= dt.NewRow();
InBlock.gif       drNew[
"CategoryID"= 11;
InBlock.gif       drNew[
"CategoryName"= "橡皮";
InBlock.gif       drNew[
"FatherID"= 3;
InBlock.gif       dt.Rows.Add( drNew );
InBlock.gif 
InBlock.gif       dsAllNodes.Tables.Add(dt);
ExpandedSubBlockEnd.gif    }

InBlock.gif 
InBlock.gif    [AjaxPro.AjaxMethod]
InBlock.gif    
public DataSet GetSubCategory(int CategoryID)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       DataSet ds 
= new DataSet();
InBlock.gif       DataTable dt 
= this.CreateStructure();
InBlock.gif       DataRow[] drSelect 
= dsAllNodes.Tables[0].Select("FatherID=" + CategoryID.ToString());
InBlock.gif       
foreach (DataRow drTemp in drSelect)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{
InBlock.gif          DataRow dr 
= dt.NewRow();
InBlock.gif          dr[
"CategoryID"= drTemp["CategoryID"];
InBlock.gif          dr[
"CategoryName"= drTemp["CategoryName"];
InBlock.gif          dr[
"FatherID"= drTemp["FatherID"];
InBlock.gif          dr[
"IsChild"= IsLeaf( int.Parse( drTemp["CategoryID"].ToString() ) );
InBlock.gif          dt.Rows.Add(dr);
ExpandedSubBlockEnd.gif       }

InBlock.gif       ds.Tables.Add(dt);
InBlock.gif       
return ds;
ExpandedSubBlockEnd.gif    }

InBlock.gif 
InBlock.gif    [AjaxPro.AjaxMethod]
InBlock.gif    
public bool IsLeaf(int Category)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
foreach(DataRow dr in dsAllNodes.Tables[0].Rows)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif           
if (dr["FatherID"!= null && int.Parse(dr["FatherID"].ToString()) == Category)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
dot.gif{
InBlock.gif              
return false;  
ExpandedSubBlockEnd.gif           }

ExpandedSubBlockEnd.gif        }

InBlock.gif        
return true;
ExpandedSubBlockEnd.gif    }

InBlock.gif 
InBlock.gif    [AjaxPro.AjaxMethod]
InBlock.gif    
public string GetNameByCategoryID(string CategoryID )
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       
foreach( DataRow dr in dsAllNodes.Tables[0].Rows )
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{
InBlock.gif          
if( dr["CategoryID"].ToString() == CategoryID.ToString() )
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{
InBlock.gif             
return dr["CategoryName"].ToString();
ExpandedSubBlockEnd.gif          }

ExpandedSubBlockEnd.gif       }

InBlock.gif       
return "";
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif }

(六). 示例代码下载:
        http://www.cnitblog.com/Files/ChengKing/AjaxPro.net_EfficientTree.rar

转载于:https://www.cnblogs.com/SUNBOY/archive/2007/02/12/648004.html

JFM7VX690T型SRAM型现场可编程门阵列技术手册主要介绍的是上海复旦微电子集团股份有限公司(简称复旦微电子)生产的高性能FPGA产品JFM7VX690T。该产品属于JFM7系列,具有现场可编程特性,集成了功能强大且可以灵活配置组合的可编程资源,适用于实现多种功能,如输入输出接口、通用数字逻辑、存储器、数字信号处理和时钟管理等。JFM7VX690T型FPGA适用于复杂、高速的数字逻辑电路,广泛应用于通讯、信息处理、工业控制、数据中心、仪表测量、医疗仪器、人工智能、自动驾驶等领域。 产品特点包括: 1. 可配置逻辑资源(CLB),使用LUT6结构。 2. 包含CLB模块,可用于实现常规数字逻辑和分布式RAM。 3. 含有I/O、BlockRAM、DSP、MMCM、GTH等可编程模块。 4. 提供不同的封装规格和工作温度范围的产品,便于满足不同的使用环境。 JFM7VX690T产品系列中,有多种型号可供选择。例如: - JFM7VX690T80采用FCBGA1927封装,尺寸为45x45mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T80-AS同样采用FCBGA1927封装,但工作温度范围更广,为-55°C到+125°C,同样使用锡银焊球。 - JFM7VX690T80-N采用FCBGA1927封装和铅锡焊球,工作温度范围与JFM7VX690T80-AS相同。 - JFM7VX690T36的封装规格为FCBGA1761,尺寸为42.5x42.5mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T36-AS使用锡银焊球,工作温度范围为-55°C到+125°C。 - JFM7VX690T36-N使用铅锡焊球,工作温度范围与JFM7VX690T36-AS相同。 技术手册中还包含了一系列详细的技术参数,包括极限参数、推荐工作条件、电特性参数、ESD等级、MSL等级、重量等。在产品参数章节中,还特别强调了封装类型,包括外形图和尺寸、引出端定义等。引出端定义是指对FPGA芯片上的各个引脚的功能和接线规则进行说明,这对于FPGA的正确应用和电路设计至关重要。 应用指南章节涉及了FPGA在不同应用场景下的推荐使用方法。其中差异说明部分可能涉及产品之间的性能差异;关键性能对比可能包括功耗与速度对比、上电浪涌电流测试情况说明、GTH Channel Loss性能差异说明、GTH电源性能差异说明等。此外,手册可能还提供了其他推荐应用方案,例如不使用的BANK接法推荐、CCLK信号PCB布线推荐、JTAG级联PCB布线推荐、系统工作的复位方案推荐等,这些内容对于提高系统性能和稳定性有着重要作用。 焊接及注意事项章节则针对产品的焊接过程提供了指导,强调焊接过程中的注意事项,以确保产品在组装过程中的稳定性和可靠性。手册还明确指出,未经复旦微电子的许可,不得翻印或者复制全部或部分本资料的内容,且不承担采购方选择与使用本文描述的产品和服务的责任。 上海复旦微电子集团股份有限公司拥有相关的商标和知识产权。该公司在中国发布的技术手册,版权为上海复旦微电子集团股份有限公司所有,未经许可不得进行复制或传播。 技术手册提供了上海复旦微电子集团股份有限公司销售及服务网点的信息,方便用户在需要时能够联系到相应的服务机构,获取最新信息和必要的支持。同时,用户可以访问复旦微电子的官方网站(***以获取更多产品信息和公司动态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值