Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

using sitemapdatasource to display list of links

Posted on 2006-07-19
4
Medium Priority
?
1,078 Views
Last Modified: 2008-01-09
Is anyone familiar with the following method used to display a subset of items in the SiteMap to be rendered on a specific menu?

http://weblogs.asp.net/dneimke/archive/2005/03/29/396103.aspx

I have tried using this method in a myriad of different ways and cannot get this to work.  It seems straightforward, but I can't get it to work.

This is the current way I'm trying to get it to work:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TopNavigationBar.ascx.cs" Inherits="UserControls_TopNavigationBar" %>
<asp:Repeater runat="server" ID="siteMapAsBulletedList" DataSourceID="SiteMapDataSource1" OnItemCommand="siteMapAsBulletedList_ItemCommand">
    <HeaderTemplate>
        <ul>
            <li><asp:HyperLink runat="server" ID="lnkHome" NavigateUrl='<%# SiteMap.RootNode.Url %>' Text='<%# SiteMap.RootNode.Title %>'></asp:HyperLink></li>
    </HeaderTemplate>
    <ItemTemplate>
        <li>
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>'></asp:HyperLink>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>
<asp:SiteMapDataSource ShowStartingNode="false" ID="SiteMapDataSource1" runat="server" />

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class UserControls_TopNavigationBar : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
   
    protected void siteMapAsBulletedList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        SiteMapNode node = e.Item.DataItem as SiteMapNode;
        string display = node["MenuLocation"];
        if (string.IsNullOrEmpty(display) || display != "top")
        {
            e.Item.Visible = false;
        }
    }
}

No errors, just doesn't display the subset of items from the sitemap I've specified.

Here is my sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/index.aspx" title="Home" MenuLocation="top">
    <siteMapNode url="~/about_us/index.aspx" title="About Us" MenuLocation="top">
      <siteMapNode url="~/about_us/mediaroom.aspx" title="Media Room" />
      <siteMapNode url="~/about_us/awards.aspx" title="Awards" />
      <siteMapNode url="~/about_us/employment.aspx" title="Employment Opportunities" />
      <siteMapNode url="~/about_us/events.aspx" title="Trade Show Calendar" />
      <siteMapNode url="~/about_us/partners.aspx" title="Partners and Alliances" />
      <siteMapNode url="~/about_us/wrcmedia.aspx" title="WRC Media" />
    </siteMapNode>
    <siteMapNode url="~/contact.aspx" title="Contact Us" MenuLocation="top" />
    <siteMapNode url="http://support.compasslearning.com" title="Customer Support" MenuLocation="top" />
    <siteMapNode url="~/sitemap.aspx" title="Site Map" MenuLocation="top" />
    <siteMapNode url="~/technology/index.aspx" title="Technology">
      <siteMapNode url="~/technology/subscription.aspx" title="Odyssey Subscription" />
      <siteMapNode url="~/technology/hosted.aspx" title="Odyssey Hosted" />
      <siteMapNode url="~/technology/enterprise.aspx" title="Odyssey Enterprise" />
    </siteMapNode>
      <siteMapNode url="~/research/index.aspx" title="Research" />
    <siteMapNode url="~/assessment/index.aspx" title="Assessment">
      <siteMapNode url="~/assessment/custom.aspx" title="Custom Assessment" />
      <siteMapNode url="~/assessment/explorer.aspx" title="CompassLearning Explorer" />
    </siteMapNode>
    <siteMapNode url="~/curriculum/index.aspx" title="Curriculum">
      <siteMapNode url="~/curriculum/prek.aspx" title="Pre-K" />
      <siteMapNode url="~/curriculum/reading.aspx" title="Reading/Language Arts" />
      <siteMapNode url="~/curriculum/writing.aspx" title="Writing" />
      <siteMapNode url="~/curriculum/math.aspx" title="Mathematics" />
      <siteMapNode url="~/curriculum/spanmath.aspx" title="Matemáticas" />
      <siteMapNode url="~/curriculum/science.aspx" title="Science" />
      <siteMapNode url="~/curriculum/socialstudies.aspx" title="Social Studies" />
      <siteMapNode url="~/curriculum/crosscurricular.aspx" title="Cross Curricular" />
      <siteMapNode url="~/curriculum/ell.aspx" title="English Language Learners" />
      <siteMapNode url="~/curriculum/specialneeds.aspx" title="Children with Spcial Needs" />
      <siteMapNode url="~/curriculum/secondary.aspx" title="Secondary" />
    </siteMapNode>
    <siteMapNode url="~/data_management/index.aspx" title="Data Management">
      <siteMapNode url="~/data_management/students.aspx" title="Managing Students" />
      <siteMapNode url="~/data_management/standards.aspx" title="Managing Standards" />
      <siteMapNode url="~/data_management/reporting.aspx" title="Managing Reporting" />
    </siteMapNode>
    <siteMapNode url="~/services/index.aspx" title="Services">
      <siteMapNode url="~/services/custservice.aspx" title="Customer Service" />
      <siteMapNode url="~/services/implementservice.aspx" title="Implementation Services" />
      <siteMapNode url="~/services/supportplan.aspx" title="Annual Support Plans" />
      <siteMapNode url="~/services/options.aspx" title="More Options" />
      <siteMapNode url="~/services/prodev.aspx" title="Professional Development" />
    </siteMapNode>
    <siteMapNode url="~/results/index.aspx" title="Results">
      <siteMapNode url="~/results/research.aspx" title="Product Research"  />
      <siteMapNode url="~/results/achievement.aspx" title="Achievement Results"  />
    </siteMapNode>
    </siteMapNode>
</siteMap>

Any help?
0
Comment
Question by:-Dman100-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:e1v
ID: 17144368
Move the code in your ItemCommand-event to the ItemCreated event of the repeater, and add a
if (node==null) return;
after
SiteMapNode node = e.Item.DataItem as SiteMapNode;

The ItemCommand event is for handling things like button-clicks inside your repeater, and it's not fired during creation of the repeater items.
0
 

Author Comment

by:-Dman100-
ID: 17146225
I received the following error:

No overload for 'siteMapAsBulletedList_ItemCreated' matches delegate 'System.Web.UI.WebControls.RepeaterItemEventHandler'

user control:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TopNavigationBar.ascx.cs"
Inherits="UserControls_TopNavigationBar" %>
<asp:Repeater runat="server" ID="siteMapAsBulletedList" DataSourceID="SiteMapDataSource1" OnItemCreated="siteMapAsBulletedList_ItemCreated">
    <HeaderTemplate>
        <ul>
            <li><asp:HyperLink runat="server" ID="lnkHome" NavigateUrl='<%# SiteMap.RootNode.Url %>' Text='<%# SiteMap.RootNode.Title %>'></asp:HyperLink></li>
    </HeaderTemplate>
    <ItemTemplate>
        <li>
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>'></asp:HyperLink>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
</asp:Repeater>
<asp:SiteMapDataSource ShowStartingNode="false" ID="SiteMapDataSource1" runat="server" />

code-behind:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;

public partial class UserControls_TopNavigationBar : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
   
    protected void siteMapAsBulletedList_ItemCreated(object source, RepeaterCommandEventArgs e)
    {
        SiteMapNode node = e.Item.DataItem as SiteMapNode;
        if (node == null) return;
        string display = node["MenuLocation"];
        if (string.IsNullOrEmpty(display) || display != "top")
        {
            e.Item.Visible = false;
        }
    }
}


Is this incorrect?

Thanks for your help
0
 
LVL 6

Accepted Solution

by:
e1v earned 2000 total points
ID: 17146269
You must replace RepeaterCommandEventArgs with  RepeaterItemEventArgs

protected void siteMapAsBulletedList_ItemCreated(object source, RepeaterItemEventArgs e)
0
 

Author Comment

by:-Dman100-
ID: 17146677
Thank you e1v...I really appreciate your help with this.  That got it working.

I have been trying to figure out how to get that to work right for several days.

Thanks again!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question