<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6126984696729141867</id><updated>2011-11-27T15:47:36.189-08:00</updated><category term='viewstate in asp .net 2.0'/><category term='ViewState'/><category term='business objects'/><category term='PageStatePersister'/><title type='text'>Smart stuff</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://nihirporecha.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6126984696729141867/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://nihirporecha.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Nihir Porecha</name><uri>http://www.blogger.com/profile/01308009045539388870</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6126984696729141867.post-3853819427917618216</id><published>2009-04-14T02:44:00.000-07:00</published><updated>2009-06-25T03:46:17.253-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='PageStatePersister'/><category scheme='http://www.blogger.com/atom/ns#' term='viewstate in asp .net 2.0'/><category scheme='http://www.blogger.com/atom/ns#' term='ViewState'/><title type='text'>New way to Store view state at Persistent Medium in .NET</title><content type='html'>Sometimes, it becomes necessity to store the view state at server side. It can be stored in session or at file IO. Most of us are aware of how to store the view state at server. If not aware of the traditional way of storing the view state at server then &lt;a href="http://pareshjagatia.blogspot.com/search/label/VIEWSTATE"&gt;check it out&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I am going to explain another way, which I think is a great example of having object orientation.&lt;br /&gt;&lt;br /&gt;.NET Provides us a class named &lt;span style="font-weight: bold;"&gt;PageStatePersister&lt;/span&gt;. Inheriting which we are going to create another class. I named it &lt;span style="font-weight: bold;"&gt;FilePageStatePersister&lt;/span&gt;.&lt;br /&gt;The class will look like below.&lt;br /&gt;&lt;br /&gt;public class FilePageStatePersister : PageStatePersister&lt;br /&gt; {&lt;br /&gt;     #region Variables&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Holds the unique id for each of the view states.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     string _id = "";&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// The folder path from where to read and write the view state files.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     string _viewStateFolderPath;&lt;br /&gt;     #endregion&lt;br /&gt;     #region Ctors&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Constructor for creating the object.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     /// &amp;lt;param name="page"&amp;gt;reference of the page&lt;br /&gt;     /// &amp;lt;param name="id"&amp;gt;unique id&lt;br /&gt;     public FilePageStatePersister(Page page, string id)&lt;br /&gt;         : base(page)&lt;br /&gt;     {&lt;br /&gt;         _id = id;&lt;br /&gt;         _viewStateFolderPath =page.Server.MapPath(Constants.VIEWSTATEPATH);&lt;br /&gt;&lt;br /&gt;     }&lt;br /&gt;     #endregion&lt;br /&gt;     #region Overrided Methods&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Load the view state from file system.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     public override void Load()&lt;br /&gt;     {&lt;br /&gt;         string viewStateData = GetViewState();&lt;br /&gt;         this.ViewState = this.StateFormatter.Deserialize(viewStateData);&lt;br /&gt;     }&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Save the view state to file system.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     public override void Save()&lt;br /&gt;     {&lt;br /&gt;         string viewStateData = this.StateFormatter.Serialize(this.ViewState);&lt;br /&gt;         StoreViewState(viewStateData);&lt;br /&gt;     }&lt;br /&gt;     #endregion&lt;br /&gt;     #region Class Methods&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Actually store the data to the file system.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     /// &amp;lt;param name="data"&amp;gt;&lt;br /&gt;     private void StoreViewState(string data)&lt;br /&gt;     {&lt;br /&gt;         StreamWriter writer = null;&lt;br /&gt;         try&lt;br /&gt;         {&lt;br /&gt;             if (!Directory.Exists(_viewStateFolderPath))&lt;br /&gt;             {&lt;br /&gt;                 Directory.CreateDirectory(_viewStateFolderPath);&lt;br /&gt;             }&lt;br /&gt;             writer = new StreamWriter(_viewStateFolderPath + _id);&lt;br /&gt;             writer.Write(data);&lt;br /&gt;         }&lt;br /&gt;         finally&lt;br /&gt;         {&lt;br /&gt;             writer.Close();&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;     /// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Actually reads the data from the file system.&lt;br /&gt;     /// &amp;lt;/summary&amp;gt;&lt;br /&gt;     /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br /&gt;     private string GetViewState()&lt;br /&gt;     {&lt;br /&gt;         string data = "";&lt;br /&gt;&lt;br /&gt;         StreamReader reader = null;&lt;br /&gt;&lt;br /&gt;         try&lt;br /&gt;         {&lt;br /&gt;             reader = new StreamReader(_viewStateFolderPath + _id);&lt;br /&gt;             data = reader.ReadToEnd();&lt;br /&gt;         }&lt;br /&gt;         finally&lt;br /&gt;         {&lt;br /&gt;             reader.Close();&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         return data;&lt;br /&gt;     }&lt;br /&gt;     #endregion&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;We need to override &lt;span style="font-weight: bold;"&gt;Save&lt;/span&gt; and &lt;span style="font-weight: bold;"&gt;Load&lt;/span&gt; methods of the class.&lt;br /&gt;&lt;br /&gt;Simple till now.&lt;br /&gt;&lt;br /&gt;The class is ready to be used.&lt;br /&gt;Now, the remaining portion is how to use it.&lt;br /&gt;I have created a PageBase class, which inherits System.Web.UI.Page class. All the asp .net pages inherits from my PageBase class instead of inheriting from System.Web.UI.Page class.&lt;br /&gt;&lt;br /&gt;We just need to override one of the properties available with System.Web.UI.Page.&lt;br /&gt;The code will look like this.&lt;br /&gt;&lt;br /&gt;/// &amp;lt;summary&amp;gt;&lt;br /&gt;     /// Get the Persiter object for storing view state.&lt;br /&gt;     /// If &amp;lt;see cref="DoSaveStateToPersistenceMedium"&amp;gt; is set to true then it will use&lt;br /&gt;     /// instance of &amp;lt;see cref="FilePageStatePersister"&amp;gt; class other wise it will use&lt;br /&gt;     /// default PageStatePersister.&lt;br /&gt;     /// &amp;lt;/see&amp;gt;&lt;br /&gt;     protected override PageStatePersister PageStatePersister&lt;br /&gt;     {&lt;br /&gt;         get&lt;br /&gt;         {&lt;br /&gt;             if (DoSaveStateToPersistenceMedium)&lt;br /&gt;             {&lt;br /&gt;                 if (_pageStatePersister == null)&lt;br /&gt;                 {&lt;br /&gt;                     string guid = "";&lt;br /&gt;&lt;br /&gt;                     if (Request[Constants.VIEWSTATEKEY] == null)&lt;br /&gt;                     {&lt;br /&gt;                         guid = Guid.NewGuid().ToString();&lt;br /&gt;                     }&lt;br /&gt;                     else&lt;br /&gt;                     {&lt;br /&gt;                         guid = Request[Constants.VIEWSTATEKEY].ToString();&lt;br /&gt;                     }&lt;br /&gt;&lt;br /&gt;                     _pageStatePersister = new FilePageStatePersister(this, guid);&lt;br /&gt;&lt;br /&gt;                     Literal literal = new Literal();&lt;br /&gt;                     literal.Text = "&amp;lt;div&amp;gt;&amp;lt;input type=\"hidden\" name=\"" + Constants.VIEWSTATEKEY + "\" value=\"" + guid + "\" /&amp;gt;&amp;lt;/div&amp;gt;";&lt;br /&gt;                     this.Form.Controls.Add(literal);&lt;br /&gt;                 }&lt;br /&gt;             }&lt;br /&gt;             else&lt;br /&gt;             {&lt;br /&gt;                 _pageStatePersister = base.PageStatePersister;&lt;br /&gt;             }&lt;br /&gt;             return _pageStatePersister;&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As I have developed a PageBase and some of the pages of the project may require the viewstate to be stored at server, I have added a property which will notify whether the viewstate will be stored at server side or it will be stored at client(which is default). This provides us the flexibility to change the behavior of the view state storing whenever required.&lt;br /&gt;&lt;br /&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6126984696729141867-3853819427917618216?l=nihirporecha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nihirporecha.blogspot.com/feeds/3853819427917618216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nihirporecha.blogspot.com/2009/04/new-way-to-store-view-state-at.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6126984696729141867/posts/default/3853819427917618216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6126984696729141867/posts/default/3853819427917618216'/><link rel='alternate' type='text/html' href='http://nihirporecha.blogspot.com/2009/04/new-way-to-store-view-state-at.html' title='New way to Store view state at Persistent Medium in .NET'/><author><name>Nihir Porecha</name><uri>http://www.blogger.com/profile/01308009045539388870</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6126984696729141867.post-7788646183692014525</id><published>2008-12-25T00:53:00.001-08:00</published><updated>2009-04-28T00:43:28.533-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='business objects'/><title type='text'>Custom Business Objects binding to Hierarchical datasource controls</title><content type='html'>I am great believer of Object Oriented Concepts and its implementation. Recently, I was looking for a class which will provide me a way to bind my business objects to a hierarchical datasource. I was unable to find it and so finally decided to develop my own hierarchical datasource.&lt;br /&gt;Here is the class which will allow us to bind any of the custom business object collection to .NET Treeview control or Menu control.&lt;br /&gt;The prerequisites are&lt;br /&gt;1) The collection should implement an interface. I named it  IHierarchySupport. The interface definition is&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;public interface IHierarchySupport&lt;t&gt;&lt;/t&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; {&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;   List&lt;t&gt;&lt;/t&gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;t&gt; GetChildren(string parentId);&lt;/t&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;   T GetParent (string childId);&lt;br /&gt;  &lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;bool HasChildren(string parentId);&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;2) Here T is a custom business object. The only consideration in developing the business object should be to override ToString() method and return the id of the object. In my case my object definition looks like&lt;br /&gt;&lt;br /&gt;public class SecurityObjectInfo&lt;br /&gt;{&lt;br /&gt;  #region Variables&lt;br /&gt;  SecurityObjectInfo _parentObject;&lt;br /&gt;  #endregion&lt;br /&gt;  public int ObjectId&lt;br /&gt;  {&lt;br /&gt;      get;&lt;br /&gt;      internal set;&lt;br /&gt;  }&lt;br /&gt;  public SecurityObjectInfo ParentObject&lt;br /&gt;  {&lt;br /&gt;      get&lt;br /&gt;      {&lt;br /&gt;          return _parentObject;&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;  public string ObjectName&lt;br /&gt;  {&lt;br /&gt;      get;&lt;br /&gt;      internal set;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public string PageName&lt;br /&gt;  {&lt;br /&gt;      get;&lt;br /&gt;      internal set;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public SecurityObjectInfo()&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 0, 0);"&gt;       &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt; public override string ToString()&lt;/span&gt;&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;        {&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;            return ObjectId.ToString();&lt;/span&gt; &lt;span style="color: rgb(255, 0, 0); font-weight: bold;"&gt;        }&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;3) Now I need a collection which will hold my business objects. As I am using CSLA framework to develop my business objects my collection is inherited from &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;ReadOnlyListBase. &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;span style="color: rgb(51, 51, 51);"&gt;I have removed data access code for having simplicity.&lt;/span&gt;&lt;/span&gt;  This collection will implement the &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchySupport &lt;/span&gt;&lt;span style="color: rgb(51, 51, 51);"&gt;interface&lt;/span&gt;. It will look like&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;public class SecurityObjects:ReadOnlyListBase&amp;lt;SecurityObjects,SecurityObjectInfo&amp;gt;,IHierarchySupport&amp;lt;SecurityObjectInfo&amp;gt;&lt;br /&gt;&lt;/span&gt;{&lt;br /&gt;  private SecurityObjects()&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt;  public static SecurityObjects GetSecurityObjects(string userName)&lt;br /&gt;  {&lt;br /&gt;      return DataPortal.Fetch&lt;securityobjects&gt; (new SingleCriteria&lt;securityobjects,string&gt;(userName));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;        #region IHierarchySupport Members&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;        public List&lt;securityobjectinfo&gt; GetChildren(string parentId)&lt;br /&gt;&lt;/securityobjectinfo&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;            List&lt;/span&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;securityobjectinfo&gt; children;&lt;/securityobjectinfo&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;            if (parentId.Equals(string.Empty))&lt;br /&gt;&lt;/span&gt;     &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;children =this.Where(childObject =&gt; childObject.ParentObject == null).ToList();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;            else&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;children = this.Where(childObject =&gt; childObject.ParentObject != null &amp;amp;&amp;amp; childObject.ParentObject.ObjectId.ToString().Equals(parentId)).ToList();&lt;br /&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;return children;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;br /&gt;public SecurityObjectInfo GetParent(string childId)&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;SecurityObjectInfo parent = null;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;      &lt;br /&gt;if (!childId.Equals(string.Empty))&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;                parent =  this.Where(childObject =&gt;   childObject.ObjectId.ToString().Equals(childId)).Single();&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;return parent;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;  &lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;public bool HasChildren(string parentId)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;        {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;List&lt;/span&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;securityobjectinfo&gt; children = this.Where(childObject =&gt; childObject.ParentObject != null &amp;amp;&amp;amp; childObject.ParentObject.ObjectId.ToString().Equals(parentId)).ToList();&lt;/securityobjectinfo&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;      &lt;br /&gt;return children.Count &gt; 0 ? true : false;&lt;br /&gt;&lt;/span&gt; &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;}&lt;/span&gt;   &lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;4) Now we are done with Business Objects part. I need a class which implements &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchicalDataSource&lt;/span&gt; and should be generic enough to accomodate any business objects collection which implements &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchySupport&lt;/span&gt; interface. So, my HierarchicalDataSource class looks like&lt;br /&gt;&lt;br /&gt;public class HierarchicalDataSource&lt;t&gt; &lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;: &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchicalDataSource&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   &lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchySupport&lt;/span&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;t&gt; _collection &lt;/t&gt;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   public HierarchicalDataSource(&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;IHierarchySupport&lt;t&gt;&lt;/t&gt;&lt;/span&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&lt;t&gt; collection&lt;/t&gt;&lt;/span&gt;)&lt;br /&gt;  {&lt;br /&gt;      this._collection = collection;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public HierarchicalDataSourceView GetHierarchicalView(string viewPath)&lt;br /&gt;  {&lt;br /&gt;      return new DataSourceView(this, viewPath);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  string GetChildrenViewPath(string viewPath, T obj)&lt;br /&gt;  {&lt;br /&gt;      return viewPath + "\\" + obj.ToString();&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  bool HasChildren(string objectId )&lt;br /&gt;  {&lt;br /&gt;      return _collection.HasChildren(objectId);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  string GetParentViewPath(string viewPath)&lt;br /&gt;  {&lt;br /&gt;      return viewPath.Substring(0, viewPath.LastIndexOf("\\"));&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  #region classes that implement required interfaces&lt;br /&gt;  class DataSourceView : HierarchicalDataSourceView&lt;br /&gt;  {&lt;br /&gt;      HierarchicalDataSource&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt; _collection;&lt;br /&gt;      string _viewPath;&lt;br /&gt;&lt;br /&gt;      public DataSourceView(HierarchicalDataSource&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt; collection, string viewPath)&lt;br /&gt;      {&lt;br /&gt;          this._collection = collection;&lt;br /&gt;          this._viewPath = viewPath;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public override IHierarchicalEnumerable Select()&lt;br /&gt;      {&lt;br /&gt;          return new HierarchicalEnumerable(_collection, _viewPath);&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  class HierarchicalEnumerable : IHierarchicalEnumerable&lt;br /&gt;  {&lt;br /&gt;      HierarchicalDataSource&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt; _collection;&lt;br /&gt;      string _viewPath;&lt;br /&gt;&lt;br /&gt;      public HierarchicalEnumerable(HierarchicalDataSource&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt; collection, string viewPath)&lt;br /&gt;      {&lt;br /&gt;          this._collection = collection;&lt;br /&gt;          this._viewPath = viewPath;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public IHierarchyData GetHierarchyData(object enumeratedItem)&lt;br /&gt;      {&lt;br /&gt;          return new HierarchyData(_collection, _viewPath,(T) enumeratedItem);&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public IEnumerator GetEnumerator()&lt;br /&gt;      {&lt;br /&gt;          string parentId = string.Empty;&lt;br /&gt;          if (_viewPath == "")&lt;br /&gt;              parentId = string.Empty;&lt;br /&gt;          else&lt;br /&gt;              parentId = _viewPath.Substring(_viewPath.LastIndexOf("\\") + 1);&lt;br /&gt;return _collection._collection.GetChildren(parentId).GetEnumerator();&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  class HierarchyData : IHierarchyData&lt;br /&gt;  {&lt;br /&gt;      HierarchicalDataSource&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt; _collection;&lt;br /&gt;      T _object;&lt;br /&gt;      string _viewPath;&lt;br /&gt;&lt;br /&gt;      public HierarchyData(HierarchicalDataSource&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;T&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt; collection, string viewPath, T obj)&lt;br /&gt;      {&lt;br /&gt;          this._collection = collection;&lt;br /&gt;          this._viewPath = viewPath;&lt;br /&gt;          this._object = obj;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public IHierarchicalEnumerable GetChildren()&lt;br /&gt;      {&lt;br /&gt;          return new HierarchicalEnumerable(_collection, _collection.GetChildrenViewPath(_viewPath, _object));&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public IHierarchyData GetParent()&lt;br /&gt;      {&lt;br /&gt;          return new HierarchyData(_collection, _collection.GetParentViewPath(_viewPath), _collection._collection.GetParent(_object.ToString()));&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public bool HasChildren&lt;br /&gt;      {&lt;br /&gt;          get&lt;br /&gt;          {&lt;br /&gt;              return _collection.HasChildren(_object.ToString());&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public object Item&lt;br /&gt;      {&lt;br /&gt;          get&lt;br /&gt;          {&lt;br /&gt;              return _object;&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public string Path&lt;br /&gt;      {&lt;br /&gt;          get&lt;br /&gt;          {&lt;br /&gt;              return _viewPath;&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      public string Type&lt;br /&gt;      {&lt;br /&gt;          get&lt;br /&gt;          {&lt;br /&gt;              return _object.ToString();&lt;br /&gt;          }&lt;br /&gt;      }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;We are done with development part :).&lt;br /&gt;5) Now we need to implement our development and let me show you how easily can we do this. My code will bind my collection of security objects to menu control.&lt;br /&gt;&lt;br /&gt;      &lt;span style="color: rgb(255, 0, 0);"&gt;menu1.DataSource = new HierarchicalDataSource&lt;/span&gt;&lt;securityobjectinfo&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;&lt;/span&gt;&lt;/securityobjectinfo&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;span style="font-weight: bold; color: rgb(255, 0, 0);"&gt;&amp;lt;SecurityObjectInfo&amp;gt;&lt;/span&gt;&lt;securityobjects&gt;&lt;securityobjects,string&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;t&gt;&lt;securityobjectinfo&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;(User.SecurityObjects);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;System.Web.UI.WebControls.MenuItemBinding binding = new System.Web.UI.WebControls.MenuItemBinding();&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            binding.TextField = "ObjectName";&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            binding.ValueField = "ObjectId";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            binding.NavigateUrlField = "PageName";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            menu1.DataBindings.Add(binding);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;            menu1.DataBind();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Done............ Isn't it cool?&lt;br /&gt;&lt;br /&gt;&lt;/securityobjectinfo&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/t&gt;&lt;/securityobjects,string&gt;&lt;/securityobjects&gt;&lt;br /&gt;&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6126984696729141867-7788646183692014525?l=nihirporecha.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://nihirporecha.blogspot.com/feeds/7788646183692014525/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://nihirporecha.blogspot.com/2008/12/custom-business-objects-binding-to.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6126984696729141867/posts/default/7788646183692014525'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6126984696729141867/posts/default/7788646183692014525'/><link rel='alternate' type='text/html' href='http://nihirporecha.blogspot.com/2008/12/custom-business-objects-binding-to.html' title='Custom Business Objects binding to Hierarchical datasource controls'/><author><name>Nihir Porecha</name><uri>http://www.blogger.com/profile/01308009045539388870</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry></feed>
