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
Solved

breadcrumbs

Posted on 2012-12-28
6
159 Views
Last Modified: 2012-12-31
Hi

I have to create a breadcrumbs trails for the Categories and their subcategories as u have seen it in many sites...

Maincetegory > Subcategory >subsubcategory > subsubsubcategory >items

This is the depth of the category..
category table i have Categoryid and categoryparentid where categoryid is linked to it... I have to link it with the below table


SELECT  [Id],      ,[Name],       parentcategoryid    
  FROM [Category]

Id      Name      parentcategoryid
1      Books              0
2      Computers      0
3      Desktops       2
4      Notebooks      2
5      Accessories      3
6      Software        2
7      Games              2
8      Electronics      0
9      Camera, photo      8

like this

and I want to have a breadcumps which shows

Books
Computers
Computers->Desktops
Computers->Notebooks
Computers->Desktops->Accessories

This should be dynamic! thanks a lot!

any help will be appreciated
0
Comment
Question by:bsarahim
  • 4
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38727579
Would this be helpful:
CREATE FUNCTION GetCategoryTrail 
(
	@p1 int
)
RETURNS nvarchar(1000)
AS
BEGIN
	DECLARE @Result nvarchar(1000)
    SELECT @Result = CASE [parentcategoryid] WHEN 0 THEN [Name] ELSE dbo.GetCategoryTrail([parentcategoryid]) + ' > ' + [Name] END
    FROM [Category]
	WHERE [Id] = @p1

	RETURN @Result
END
GO

Open in new window

Then call it like this:
SELECT [Id], [Name], dbo.GetCategoryTrail([Id]) AS [Trail]
FROM [Category]

Open in new window

0
 

Author Comment

by:bsarahim
ID: 38729098
Thanks for that and it is working!

I'm little confused, how do I can show

Computers->Desktops->Accessories     (display)

When I click Accessories from sitemap or breadcumps, that will show accessories items

and when I click on the desktop, it should show the desktop items.. whether I should write asp.net routing?


Im aware of how to show the items based on the category id via datalist/gridview...
delete2.png
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38729190
I'm not sure what you're asking, it sounds like you want to DataBind a label the same way you do with a grid? I'd have to see a bit more of your current page and/or code (showing the connection and category selection) to try to show you a way to do this in the same way, I would normally use a piece of code in the page load that reads the result of a SQL command using the current category id as parameter but maybe you're using 'asp:' tags to bind the data?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:bsarahim
ID: 38729242
let me simplify

Let say I have menu where categories are being displayed, which is hardcoded in jquery, div tags

Under computers Menu category I have Accessories link, when the user click the Accessories.

after above menu,  the display should show Computers ->Desktops->Accessories
All the computer, desktop, accessories, are individual hyperlinks


Hope you understood, and im going to second

2nd requirement, based on the above requirement:

when I click any of above  computer-> desktop->, accessories , I will fetch the data based on the category code in the datalist...

Pls let me know, if it is not clear...
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38729398
I think both requirements can be met by having the function return html links:
ALTER FUNCTION GetCategoryTrail 
(
	@p1 int
)
RETURNS nvarchar(1000)
AS
BEGIN
	DECLARE @Result nvarchar(1000)
    SELECT @Result = CASE [parentcategoryid]
			WHEN 0 THEN '<a href="yourpage.aspx?catid=' + convert(nvarchar, [Id]) + '">' + [Name] + '</a>'
			ELSE dbo.GetCategoryTrail([parentcategoryid]) + ' &gt; ' + '<a href="yourpage.aspx?catid=' + convert(nvarchar, [Id]) + '">' + [Name] + '</a>'
		END
    FROM [Category]
	WHERE [Id] = @p1

	RETURN @Result
END
GO

Open in new window

make sure the page and parameter name are changed (twice) to match your project.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38729448
Here's one way to work with the output generated by the function as changed in my previous post. Note that I used the pagename and querystringparameter name to match the arbitrary examples I used.

yourpage.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="yourpage.aspx.vb" Inherits="WebAppQ_27979539.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=.\sqlexpress;User Id=ee;Password=ee;" SelectCommand="SELECT dbo.GetCategoryTrail([Id]) FROM [Category] WHERE [Id] = @Id">
        <SelectParameters><asp:QueryStringParameter Type="Int32" Name="Id" QueryStringField="catid" DefaultValue="5" /></SelectParameters>
    </asp:SqlDataSource>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>
    </div>
    </form>
</body>
</html>

Open in new window

yourpage.aspx.vb:
Imports System.Data.SqlClient

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim dv As DataView = SqlDataSource1.Select(New DataSourceSelectArguments())
        Label1.Text = dv.Table.Rows(0).Item(0)
    End Sub

End Class

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

837 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