This is a migrated thread and some comments may be shown as answers.

SiteMap with SQLDataSource

5 Answers 73 Views
SiteMap
This is a migrated thread and some comments may be shown as answers.
Geoff
Top achievements
Rank 1
Geoff asked on 22 Nov 2013, 03:29 PM
Hi,
    As a newbie I'm having trouble getting started with the site map control. Just as a working example for myself, I tried to setup an ultra simple breadcrumb but I failed so I need some help. My page looks like this:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="user_Default" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
 
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all" DecorationZoneID="rfd-demo-zone"></telerik:RadFormDecorator>
 
        <div>
            <telerik:RadSiteMap runat="server" ID="RadSiteMap1" DataSourceID="SqlDataSource1"
                    DataFieldID="NodeNo" DataFieldParentID="ParentNodeNo"
                    DataTextField="NodeText" DataNavigateUrlField="NodeURL">
                <DefaultLevelSettings ListLayout-RepeatDirection="Horizontal" SeparatorText="/" Layout="Flow" />
            </telerik:RadSiteMap>
 
            <asp:SqlDataSource runat="server" ID="SqlDataSource1"
                ConnectionString="<%$ ConnectionStrings:RAMtrack %>"
                ProviderName="<%$ ConnectionStrings:RAMtrack.ProviderName %>"
                SelectCommand="SELECT NodeNo, ParentNodeNo, NodeText, NodeURL FROM tbl_SiteMap">
            </asp:SqlDataSource>
     
        </div>
    </form>
</body>
</html>

The table (tbl_SiteMap) in my data source looks like this:
NodeNo    ParentNodeNo    NodeText    NodeURL
1                0                         MainMenu    user/MainMenu.aspx
2                1                         Logbook       user/Logbook.aspx

When I run the page, I get this error: "This constraint cannot be enabled as not all values have corresponding parent values."
I've only got two nodes, they both have an entry for Parent Node so I can't tell what the problem is. Can you help?

Regards

Geoff

5 Answers, 1 is accepted

Sort by
0
Geoff
Top achievements
Rank 1
answered on 26 Nov 2013, 10:46 AM
Right well I read here that the root node ParentID must be NULL, so that's one problem sorted. The next two snags are: 

1) Even though I had two entries in my SiteMap table, only one is displayed. I added a tooltip programmatically using the NodeDataBound event and found (using a break point) that both rows are read from the table.

2) The DataNavigatUrlField property is not picking up data from the "NodeURL" column in the table. I've set it programmatically OK in the NodeDatabound event.
Protected Sub RadSiteMap1_NodeDataBound(ByVal sender As Object, ByVal e As RadSiteMapNodeEventArgs)
    Dim nodeData As DataRowView = TryCast(e.Node.DataItem, DataRowView)
    e.Node.ToolTip = nodeData("Tooltip").ToString()
    e.Node.NavigateUrl = nodeData("NodeURL").ToString()
End Sub


My Page code now looks like this:
<telerik:RadSiteMap runat="server" ID="RadSiteMap1" DataSourceID="ds_SiteMap" OnNodeDataBound="RadSiteMap1_NodeDataBound"
    DataFieldID="NodeNo" DataFieldParentID="ParentNodeNo" DataTextField="NodeText" DataNavigatUrlField="NodeURL">
    <DefaultLevelSettings ListLayout-RepeatDirection="Horizontal" SeparatorText="/" Layout="Flow" />
</telerik:RadSiteMap>
 
<asp:SqlDataSource runat="server" ID="ds_SiteMap"
    ConnectionString="<%$ ConnectionStrings:RAMtrack %>"
    ProviderName="<%$ ConnectionStrings:RAMtrack.ProviderName %>"
    SelectCommand="SELECT NodeNo, ParentNodeNo, NodeText, NodeURL, Tooltip FROM tbl_SiteMap">
</asp:SqlDataSource>

Once rendered, it looks like this:
<div id="ctl00_sm_RAMTrackBreadCrumb" class="RadSiteMap RadSiteMap_WebBlue" DataNavigatUrlField="NodeURL">
    <ul class="rsmFlow rsmLevel rsmOneLevel">
        <li class="rsmItem"><a class="rsmLink" href="MainMenu.aspx" title="Return to the Main Menu">MainMenu</a></li>
    </ul><input id="ctl00_sm_RAMTrackBreadCrumb_ClientState" name="ctl00_sm_RAMTrackBreadCrumb_ClientState" type="hidden" />
</div>
As you can see, my second node is missing. I tried adding a third too but got the same result. However, if I remove 'Layout="Flow"' from the DefaultLevelSettings, then all my node items are displayed in a vertical menu.









0
Hristo Valyavicharski
Telerik team
answered on 27 Nov 2013, 01:06 PM
Hi Geoff,

All root items nodes must have "null" value for the ParentNodeNo. And the NavigateURL property must have this format - "http://www." for example: "http://www.telerik.com". Sample project is attached.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Geoff
Top achievements
Rank 1
answered on 27 Nov 2013, 03:52 PM
Hristo,
    Thank you for your reply, that all makes sense. However, I don't believe that this addresses one of the problems I have, which is that I am only getting the first item in the SiteMap displayed.

I notice that the code you sent me has it the Layout property set to "List", When I change it to "Flow", it then only shows the first item on the site map. This problem more than the other two issues is completely crippling my ability to use this control. I want to use the control for a breadcrumb trail.

Regards

Geoff
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 02 Dec 2013, 11:12 AM
Hi Geoff,

Yes this is how the "Flow" Layout works. For additional information please read this help topic. I would suggest that you to look at this online demo http://demos.telerik.com/aspnet-ajax/menu/examples/programming/showpath/defaultcs.aspx?Page=Open%20Classes%20Training to see how the breadcrumb is implemented with  flow layout.

Regards,
Hristo Valyavicharski
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Geoff
Top achievements
Rank 1
answered on 05 Dec 2013, 02:31 PM
Hristo,
    Many thanks for your response. I did start with that demo but had difficulty untangling the menu control and the breadcrumb sitemap control. However, on your advice I went back to it, had another go and got it to work. I used the PageLoad event to call a routine that built the menu structure (from the database), which I then passed the DataBindBreadCrumbSiteMap routine. It works fine.

Regards

Geoff
Tags
SiteMap
Asked by
Geoff
Top achievements
Rank 1
Answers by
Geoff
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or