Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

breadcrumbs

Posted on 2012-12-28
6
Medium Priority
?
166 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
Independent Software Vendors: 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!

 

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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

886 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