|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom TreeNode for asp.net 2.0 treeview controlThe child nodes will be of different types, meaning they will have different attributes and different tables -Root --Service1 (select * from services) value = serviceID = 1 ---Database1 (select * from databases where serviceID = ?) ---Website1 (select * from websites where serviceID = ?) When I click on a node, I want to display attributes of that node in the right pane. I have handled this before in a windows application by creating a custom treeNode that has an extra field for type (service, database or website). Here is my custom tree node and my enumeration for type Public Enum NodeType Service Application Database Website End Enum Public Class CustomTreeNode Inherits TreeNode Private _ntype As NodeType Public Property NType() As NodeType Get Return _ntype End Get Set(ByVal value As NodeType) _ntype = value End Set End Property Public Sub New(ByVal text As String, ByVal value As String, ByVal nType As NodeType) MyBase.New(text, value) _ntype = nType End Sub Public Sub New() MyBase.New() End Sub End Class And I get an error in this function Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate If e.Node.ChildNodes.Count = 0 Then Select Case e.Node.Depth Case 0 FillAuthors(e.Node) Case 1 FillTitlesForAuthors(e.Node) Case 2 FillDatabase(e.Node) End Select End If End Sub Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to type 'CustomTreeNode' I'm not really sure how to make this work. I can give more code samples as needed, but I just need someone who can point me in the right direction. Is there some other function or property of the treenode I need to override, do I need to create a custom treeview control and override some event in it? Hi Rickey,
Welcome. As for the ASP.NET 2.0 TreeView control, we can create custom control to derived from it , also define our custom TreeNode class.... Also, currently I'm also discussing such similiar question with other guy in the newsgroup, here is the web link to the thread: #Inheriting from the TreeNode class http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet.webc ontrols/browse_thread/thread/b0f3459b35105353/df2f38d4c2b2dc20?lnk=st&q=Inhe riting+from+the+TreeNode+class&rnum=1&hl=en#df2f38d4c2b2dc20 Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | From: "Rickey Whitworth" <rickey@community.nospam> microsoft.public.dotnet.framework.aspnet.webcontrols:32567| Subject: Custom TreeNode for asp.net 2.0 treeview control | Date: Wed, 18 Jan 2006 10:48:31 -0600 | Lines: 76 | X-Priority: 3 | X-MSMail-Priority: Normal | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527 | X-RFC2646: Format=Flowed; Original | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 | Message-ID: <#Xwvw8EHGHA.3***@TK2MSFTNGP09.phx.gbl> | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols | NNTP-Posting-Host: 66.182.150.119 | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols | | I want to display a treeview control that is tied to a sql database. | | The child nodes will be of different types, meaning they will have different | attributes and different tables | | -Root | --Service1 (select * from services) value = serviceID = 1 | ---Database1 (select * from databases where serviceID = ?) | ---Website1 (select * from websites where serviceID = ?) | | When I click on a node, I want to display attributes of that node in the | right pane. I have handled this before in a windows application by creating | a custom treeNode that has an extra field for type (service, database or | website). | | Here is my custom tree node and my enumeration for type | | Public Enum NodeType | Service | Application | Database | Website | End Enum | | Public Class CustomTreeNode | Inherits TreeNode | | Private _ntype As NodeType | | Public Property NType() As NodeType | Get | Return _ntype | End Get | Set(ByVal value As NodeType) | _ntype = value | End Set | End Property | | Public Sub New(ByVal text As String, ByVal value As String, ByVal | nType As NodeType) | MyBase.New(text, value) | _ntype = nType | End Sub | | Public Sub New() | MyBase.New() | End Sub | End Class | | And I get an error in this function | | Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As | System.Web.UI.WebControls.TreeNodeEventArgs) Handles | TreeView1.TreeNodePopulate | If e.Node.ChildNodes.Count = 0 Then | Select Case e.Node.Depth | Case 0 | FillAuthors(e.Node) | Case 1 | FillTitlesForAuthors(e.Node) | Case 2 | FillDatabase(e.Node) | End Select | End If | End Sub | | | Unable to cast object of type 'System.Web.UI.WebControls.TreeNode' to type | 'CustomTreeNode' | | I'm not really sure how to make this work. I can give more code samples as | needed, but I just need someone who can point me in the right direction. Is | there some other function or property of the treenode I need to override, do | I need to create a custom treeview control and override some event in it? | | |
Help with GridView Update w/ Object Data Source needed
XHTML 1.1 and DIV 1 pixel in height ViewState properties and mapped properties don't work well togethe How do I create a custom webcontrol that can have xml inside it's tag? cache and detailsview, all data controls problem Menu Control - Templates how to get changed text from web control textbox Dropdownlist causes blank screen A bug? Transparent Dynamic Item! Calendar control to display image on Mondays |
|||||||||||||||||||||||