Ext.Net TreePanel 修改Icon图标

 

 

分类: Ext.Net


1、默认icon

          

2、自定义icon

          

完整的代码,文件WebForm2.aspx中代码

[html] view plaincopy
 
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="ext_SMS.WebForm2" %>  
  2. <%@ Import Namespace="System.Collections.Generic" %>  
  3. <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>  
  4.   
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  6.   
  7.   
  8. <html xmlns="http://www.w3.org/1999/xhtml">  
  9.   
  10. <head id="Head1" runat="server">  
  11.   <title>改变TreePanel Icon图标</title>  
  12.   style type="text/css">   //自定义样式  
  13.    .add {  
  14.     background-image: url(image/query.jpg) !important;  
  15.    }  
  16.   </style>  
  17. </head>  
  18. <body>  
  19.     <form id="Form2" runat="server">  
  20.         <ext:ResourceManager ID="ResourceManager1" runat="server" />  
  21.           
  22.         <ext:Viewport ID="Viewport1" runat="server">  
  23.             <Items>  
  24.                 <ext:BorderLayout ID="BorderLayout1" runat="server">  
  25.                     <West>  
  26.                          <ext:TreePanel   
  27.                             ID="TreePanel1"   
  28.                             runat="server"   
  29.                             Title="Tree"   
  30.                             Width="200"  
  31.                             AutoHeight="true"   
  32.                             Border="false">  
  33.                                 <Root>  
  34.                                 <ext:AsyncTreeNode Text="系统功能模块" NodeID="root" Expanded="true"   Icon="ApplicationHome">  
  35.                                 </ext:AsyncTreeNode>  
  36.                                 </Root>  
  37.                                 <Loader>  
  38.                                     <ext:PageTreeLoader RequestMethod="POST" OnNodeLoad="GetReportList" PreloadChildren="true">  
  39.                                         <EventMask ShowMask="true" Target="Parent" Msg="Loading..." />  
  40.                                     </ext:PageTreeLoader>  
  41.                                 </Loader>  
  42.                                 <Listeners>  
  43.                                     <Click Handler="if(node.isLeaf()){e.stopEvent();loadExample(node);}" />  
  44.                                 </Listeners>                       
  45.                         </ext:TreePanel>                          
  46.                     </West>                     
  47.                     <Center>  
  48.                        <ext:TabPanel ID="Pages" runat="server" EnableTabScroll="true" />  
  49.                     </Center>  
  50.                 </ext:BorderLayout>  
  51.             </Items>  
  52.         </ext:Viewport>    
  53.     </form>  
  54. </body>  
  55. </html>  


 

 后台文件WebForm2.aspx.cs中代码:

[csharp] view plaincopy
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using Ext.Net;  
  8. using System.Data;  
  9.   
  10. namespace ext_SMS  
  11. {  
  12.     public partial class WebForm2 : System.Web.UI.Page  
  13.     {  
  14.   
  15.         protected void Page_Load(object sender, EventArgs e)  
  16.         {  
  17.         }  
  18.   
  19.         protected void GetReportList(object sender, NodeLoadEventArgs e)  
  20.         {  
  21.             string prefix = e.ExtraParams["prefix"] ?? "";  
  22.             if (!string.IsNullOrEmpty(e.NodeID))  
  23.             {  
  24.                 for (int i = 1; i < 6; i++)  
  25.                 {  
  26.                     AsyncTreeNode asyncNode = new AsyncTreeNode();  
  27.                     asyncNode.Text = prefix + e.NodeID + i;  
  28.                     asyncNode.NodeID = e.NodeID + i;  
  29.                     e.Nodes.Add(asyncNode);  
  30.                 }  
  31.                 for (int i = 6; i < 11; i++)  
  32.                 {  
  33.                     Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();  
  34.                     treeNode.Text = prefix + e.NodeID + i;  
  35.                     treeNode.NodeID = e.NodeID + i;  
  36.                     treeNode.Leaf = true;  
  37.                     // treeNode.Icon = Icon.Accept;         //注意此处设置不起作用  
  38.                      treeNode.IconCls = "add";     //设置自定义样式  
  39.                     e.Nodes.Add(treeNode);  
  40.                 }  
  41.             }  
  42.         }  
  43.     }      
  44. }  

注意:图片位于image文件夹下,名称query.jpg 


3、需要默认样式时,不设置自定义样式即可。

      去掉这句:treeNode.IconCls = "add"; //设置自定义样式

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。