Cấp bậc tác giả:

DOTNET

Bằng cách nào thiết lập thuộc tính mở rộng trong TreeView Control Asp.Net

Được viết bởi QuangIT ngày 05/05/2013 lúc 12:36 PM
Có nhiều bạn thắc mắc là làm thế nào khi hiển thị TreeView thay vì mặc định nó mở ra hết các node, thì giờ nó sẽ đóng lại các node chỉ hiển thị node gốc thôi.
  • 0
  • 9736
Tải tệp tin: Click ở đây

Bằng cách nào thiết lập thuộc tính mở rộng trong TreeView Control Asp.Net

Có nhiều bạn thắc mắc là làm thế nào khi hiển thị TreeView thay vì mặc định nó mở ra hết các node, thì giờ nó sẽ đóng lại các node chỉ hiển thị node gốc thôi.

treeviewcontrol01.jpgtreeviewcontrol02.jpg

Các bạn cần quan tâm thuộc tính ExpandDepth của TreeView.
Nếu để ExpandDepth="0", nó sẽ hiển thị gốc cha(gốc lớn nhất)
Nếu để ExpandDepth="1", nó sẽ hiển thị gốc con(gốc thứ 2)
Không có ExpandDepth, nó sẽ hiển thị tất cả các node

Tại trang Aspx thêm code này vào:

<div>  
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />  
        <asp:TreeView   
             ID="TreeView1"  
             runat="server"  
             DataSourceID="SiteMapDataSource1"  
             Width="250"  
             ForeColor="DodgerBlue"  
             Font-Bold="true"  
             Font-Italic="true"  
             BorderColor="SkyBlue"  
             BorderWidth="2"  
             ExpandDepth="1"  
             >  
        </asp:TreeView>  
    </div>   

Tạo Web.Sitemap tương tự như bên dưới:

<?xml version="1.0" encoding="utf-8" ?>  
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >  
    <siteMapNode url="Default.aspx" title="Home"  description="Home Page">  
      <siteMapNode url="StandardToolBox.aspx" title="StandardToolBox" description="StandardToolBox Controls">  
        <siteMapNode url="AdRotatorExample.aspx" title="AdRotator"  description="AdRotator Example" />  
        <siteMapNode url="BulletedListExample.aspx" title="BulletedList"  description="BuulletedList Example" />  
        <siteMapNode url="ButtonExample.aspx" title="Button"  description="Button Example" />  
        <siteMapNode url="CalendarExample.aspx" title="Calendar"  description="Calendar Example" />  
      </siteMapNode>  
      <siteMapNode url="DataToolBox.aspx" title="DataToolBox" description="DataToolBox controls">  
        <siteMapNode url="ListViewExample.aspx" title="ListView"  description="ListView Example" />  
        <siteMapNode url="GridViewExample.aspx" title="GridView"  description="GridView Example" />  
      </siteMapNode>  
      <siteMapNode url="NavigationToolbox.aspx" title="Navigation Toolbox" description="NavigationToolbox controls">  
        <siteMapNode url="MenuExample.aspx" title="Menu"  description="Menu Example" />  
        <siteMapNode url="SiteMapPathExample.aspx" title="SiteMapPath"  description="SiteMapPath Example" />  
        <siteMapNode url="TreeViewExample.aspx" title="TreeView"  description="TreeView Example" />  
      </siteMapNode>  
    </siteMapNode>  
</siteMap>  

Nguồn bài viết: Dngaz.com

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML