|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Permissions;
namespace HierarchyExample {
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public class CategoryDataSource : HierarchicalDataSourceControl, IHierarchicalDataSource {
public CategoryDataSource() : base() { }
// Return a strongly typed view for the current data source control.
private CategoryDataSourceView view = null;
protected override HierarchicalDataSourceView GetHierarchicalView(string viewPath) {
if (null == view) {
view = new CategoryDataSourceView(viewPath);
}
return view;
}
// This can be used declaratively. To enable declarative use,
// override the default implementation of CreateControlCollection
// to return a ControlCollection that you can add to.
protected override ControlCollection CreateControlCollection() {
return new ControlCollection(this);
}
}
public class CategoryDataSourceView : HierarchicalDataSourceView {
private string _viewPath;
public CategoryDataSourceView(string viewPath) {
_viewPath = viewPath;
}
public override IHierarchicalEnumerable Select() {
CategoryCollection collection = new CategoryCollection();
foreach (Category category in Common.GetCategoryData()) {
if (category.ParentId == 0)
collection.Add(category);
}
return collection;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Scott Piegdon works full time as a Director of Quality Control for a software development company specializing Credit Union Member Services. He has experience as a Vice President of Information Technologies for a hosted ERP (Enterprise Resource Planning) company. He also runs a Web Design Services company (http://www.simplifyitwebdesign.com). He has a beautiful and wonderful wife, and two fantastic children. He loves to develop applications that others find not only easy to use and pleasing to the eye, but also provide un-surpassing functionality. He has been developing websites for over 12 years, and programming professionally for 9 of them. He has worked with dozens of database, scripting, procedural and compiled languages over the years, most recently specializing in Microsoft.Net C# 2.0 with ASP.Net backed by SQL Server 2005.
"Hopefully I can pass along some of the insight and knowledge I have acquired over the years to those curious enough to read it." - Scott Piegdon