nevím jestli jsem pochopil dobře to slovo slinkujete znamená to doufám např kodově toto
AddNode(a,root)
pokud ne tak jsem uplně blbej. No a zasekl jsem se na přidávání příspěvků do témat, pokud totiž vytvářím topici tím to kódem
While TopicReader.Read()
Dim Topic As New SiteMapNode(Me, TopicReader(Me.UrlTopic), String.Format(Me.UrlFormatTopic, TopicReader(Me.UrlTopic)), TopicReader(Me.TitleTopic))
AddNode(Topic, root)
List.Add(TopicReader(Me.UrlTopic), Topic)
End While
tak se každá topiková sitemapnode jmenuje stejně tudíš když pak chci přidat příspěvek tímto kódem
While PostReader.Read()
Dim Post As New SiteMapNode(Me, Guid.NewGuid().ToString(), String.Format(Me.UrlFormatPost, PostReader(Me.UrlPost)), PostReader(Me.TitlePost))
Dim a As Integer = PostReader(Me.UrlPost)
Dim c As SiteMapNode = List(a)
AddNode(Post, c)
End While
tak to není možné protože každý topikový objekt sitemapnode má stejný název to jest topic a z toho vyplívá že jsem to asi celé zase špatně pochopil a nevím co dál .... zde bych ještě dal celý kód který jsem vytvořil .... achjo :(
<add name="CategoriesSitemapProvider" type="SqlSiteMapProvider"
TitleRoot="Seznam" UrlRoot="~/Default.aspx"
ConnectionStringName="GrrConnectionString"
CommandTopic="SELECT [Id],[Topic] FROM [Topics] ORDER BY [Id]"
TitleTopic="Topic"
UrlTopic="Id" UrlFormatTopic="~/ListTopic.aspx?Id={0}"
CommandPost="SELECT [Id],[Name],[IdTopic] FROM [Posts]"
TitlePost="Name"
IdTopicPost ="IdTopic"
UrlPost="Id" UrlFormatPost="~/Default.aspx?Id={0}" />
a
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Data.SqlClient
Imports System.Collections.Generic
Public Class SqlSiteMapProvider
Inherits StaticSiteMapProvider
Private root As SiteMapNode
Public Overrides Function BuildSiteMap() As System.Web.SiteMapNode
SyncLock Me
If root Is Nothing Then 'pokud je třeba generovat, generujeme
'vytvořit kořenovou položku
root = New SiteMapNode(Me, Guid.NewGuid().ToString(), Me.UrlRoot, Me.TitleRoot)
'podpoložky natáhnout z databáze
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings(Me.ConnectionStringName).ConnectionString)
Dim TopicCom As New SqlCommand(Me.CommandTopic, con)
Dim PostCom As New SqlCommand(Me.CommandPost, con)
con.Open()
Dim TopicReader As SqlDataReader = TopicCom.ExecuteReader()
Dim List As New Dictionary(Of Integer, SiteMapNode)
While TopicReader.Read()
Dim Topic As New SiteMapNode(Me, TopicReader(Me.UrlTopic), String.Format(Me.UrlFormatTopic, TopicReader(Me.UrlTopic)), TopicReader(Me.TitleTopic))
AddNode(Topic, root)
List.Add(TopicReader(Me.UrlTopic), Topic)
End While
TopicReader.Close()
Dim PostReader As SqlDataReader = PostCom.ExecuteReader()
While PostReader.Read()
Dim Post As New SiteMapNode(Me, Guid.NewGuid().ToString(), String.Format(Me.UrlFormatPost, PostReader(Me.UrlPost)), PostReader(Me.TitlePost))
Dim a As Integer = PostReader(Me.UrlPost)
Dim c As SiteMapNode = List(a)
AddNode(Post, c)
End While
PostReader.Close()
con.Close()
End If
Return root 'vrátíme kořenovou položku
End SyncLock
End Function
Protected Overrides Function GetRootNodeCore() As System.Web.SiteMapNode
Return BuildSiteMap()
End Function
#Region "Declared"
#Region "Root and ConnectionString"
Private _TitleRoot As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property TitleRoot() As String
Get
Return _TitleRoot
End Get
Set(ByVal value As String)
_TitleRoot = value
End Set
End Property
Private _UrlRoot As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property UrlRoot() As String
Get
Return _UrlRoot
End Get
Set(ByVal value As String)
_UrlRoot = value
End Set
End Property
Private _ConnectionStringName As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property ConnectionStringName() As String
Get
Return _ConnectionStringName
End Get
Set(ByVal value As String)
_ConnectionStringName = value
End Set
End Property
#End Region
#Region "Topic"
Private _CommandTopic As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property CommandTopic() As String
Get
Return _CommandTopic
End Get
Set(ByVal value As String)
_CommandTopic = value
End Set
End Property
Private _TitleTopic As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property TitleTopic() As String
Get
Return _TitleTopic
End Get
Set(ByVal value As String)
_TitleTopic = value
End Set
End Property
Private _UrlTopic As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property UrlTopic() As String
Get
Return _UrlTopic
End Get
Set(ByVal value As String)
_UrlTopic = value
End Set
End Property
Private _UrlFormatTopic As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property UrlFormatTopic() As String
Get
Return _UrlFormatTopic
End Get
Set(ByVal value As String)
_UrlFormatTopic = value
End Set
End Property
#End Region
#Region "Post"
Private _CommandPost As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property CommandPost() As String
Get
Return _CommandPost
End Get
Set(ByVal value As String)
_CommandPost = value
End Set
End Property
Private _TitlePost As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property TitlePost() As String
Get
Return _TitlePost
End Get
Set(ByVal value As String)
_TitlePost = value
End Set
End Property
Private _IdTopicPost As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property IdTopicPost() As String
Get
Return _IdTopicPost
End Get
Set(ByVal value As String)
_IdTopicPost = value
End Set
End Property
Private _UrlPost As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property UrlPost() As String
Get
Return _UrlPost
End Get
Set(ByVal value As String)
_UrlPost = value
End Set
End Property
Private _UrlFormatPost As String
''' <summary>
''' Název kořenové položky
''' </summary>
Public Property UrlFormatPost() As String
Get
Return _UrlFormatPost
End Get
Set(ByVal value As String)
_UrlFormatPost = value
End Set
End Property
#End Region
#End Region
#Region "Initialize"
Public Overrides Sub Initialize(ByVal name As String, ByVal attributes As System.Collections.Specialized.NameValueCollection)
MyBase.Initialize(name, attributes)
'načíst hodnoty parametrů z konfigurace
'Root and ConnectionString
If attributes("TitleRoot") IsNot Nothing Then
Me.TitleRoot = attributes("TitleRoot")
Else : Throw New ArgumentException("TitleRoot")
End If
If attributes("UrlRoot") IsNot Nothing Then
Me.UrlRoot = attributes("UrlRoot")
Else : Throw New ArgumentException("UrlRoot")
End If
If attributes("ConnectionStringName") IsNot Nothing Then
Me.ConnectionStringName = attributes("ConnectionStringName")
Else : Throw New ArgumentException("ConnectionStringName")
End If
'Topic
If attributes("CommandTopic") IsNot Nothing Then
Me.CommandTopic = attributes("CommandTopic")
Else : Throw New ArgumentException("CommandTopic")
End If
If attributes("TitleTopic") IsNot Nothing Then
Me.TitleTopic = attributes("TitleTopic")
Else : Throw New ArgumentException("TitleTopic")
End If
If attributes("UrlTopic") IsNot Nothing Then
Me.UrlTopic = attributes("UrlTopic")
Else : Throw New ArgumentException("UrlTopic")
End If
If attributes("UrlFormatTopic") IsNot Nothing Then
Me.UrlFormatTopic = attributes("UrlFormatTopic")
Else : Throw New ArgumentException("UrlFormatTopic")
End If
'Post
If attributes("CommandPost") IsNot Nothing Then
Me.CommandPost = attributes("CommandPost")
Else : Throw New ArgumentException("CommandPost")
End If
If attributes("TitlePost") IsNot Nothing Then
Me.TitlePost = attributes("TitlePost")
Else : Throw New ArgumentException("TitlePost")
End If
If attributes("IdTopicPost") IsNot Nothing Then
Me.IdTopicPost = attributes("IdTopicPost")
Else : Throw New ArgumentException("IdTopicPost")
End If
If attributes("UrlPost") IsNot Nothing Then
Me.UrlPost = attributes("UrlPost")
Else : Throw New ArgumentException("UrlPost")
End If
If attributes("UrlFormatPost") IsNot Nothing Then
Me.UrlFormatPost = attributes("UrlFormatPost")
Else : Throw New ArgumentException("UrlFormatPost")
End If
End Sub
#End Region
End Class
|