Saturday, February 25, 2012

creating a data driven hierarchial navigation

Hi need to create navigation that gets populated via database and is role based. below is the sql

CREATETABLE [TopMenu](

[MenuID] [int]IDENTITY(1, 1)NOTNULL,

[Text] [varchar](50)COLLATE SQL_Latin1_General_CP1_CI_ASNULL,

[Description] [varchar](255)COLLATE SQL_Latin1_General_CP1_CI_ASNULL,

[ParentID] [int]NULL,

CONSTRAINT [PK_Menu]PRIMARYKEYCLUSTERED

(

[MenuID]

)ON [PRIMARY]

)ON [PRIMARY]

GO

INSERTINTO TopMENU

Select'Property','Property',NULL

UNION ALLSelect'Portfolio','Portfolio',NULL

UNION ALLSelect'Capital Expenditure','PortfolioCapex', 1

UNION ALLSelect'Depreciation','PortfolioDepreciation', 1

UNION ALLSelect'Condition Audit','PortfolioCondition', 1

UNION ALLSelect'Historical Expenditure','PortfolioHisEx', 1

UNION ALLSelect'Property Details','PropertyDetail', 2

UNION ALLSelect'Assets','PropertyAsset', 2

UNION ALLSelect'Depreciation','PropertyDepreciation', 2

UNION ALLSelect'Capital Expenditure','PropertyExpenditure', 2

UNION ALLSelect'Insurance','PropertyInsurance', 2

UNION ALLSelect'Documents','PropertyDocuments', 2

UNION ALLSelect'Capex','PortfolioCapex', 3

UNION ALLSelect'Graph','PortfolioCapexGraph', 3

UNION ALLSelect'Graph','PortfolioDepreciationGraph', 4

UNION ALLSelect'Current Depreciation','PortfolioDepreciation', 4

UNION ALLSelect'WDV & Depreciation','PortfolioDepreciationWDV', 4

UNION ALLSelect'Assets','PropertyAsset', 8

UNION ALLSelect'Capex','PropertyCapex', 8

UNION ALLSelect'Depreciation','PropertyDepreciation', 8

UNION ALLSelect'Condition','PropertyCondition', 8

UNION ALLSelect'Expenditure','PropertyExpenditure', 8

UNION ALLSelect'Disposed','PropertyDisposed', 8

UNION ALLSelect'Capital Ex','PropertyExpenditure', 10

UNION ALLSelect'Capital Ex Graph','PropertyExpenditureGraph', 10

GO

now clearly, I will have two top level navigation

property and portfolio. both property will have subsequent navigation and those subsequest navigation may or may not have another sets of navigation.

I need to display in a row style not in a drop down style for eg. If I am in portfolio link the navigation structure should be as below

Portfolio

Capital Expenditure | Depreciation | Condition Audit | Historical Expenditure

Capex | Graph

by default Capex should be selected. it should also highlight Portfolio, Capital Expenditure and Capex as Capex's parent is Capital Expenditure and Portfolio

I was thinking of using a 3 level datagrid. could someone please help me I am using asp.net 2.0 web application project with vb.net and sql server 2005

thanks in advance

Have you looked at the menu class available from the toolbar? I know it works with a hierarchical xml file, it might work with a database source also.

If it does, I think it will do what you want UI-wise.

|||I am doing it in webform not windows form. does it support that?|||

foremorecoast:

I am doing it in webform not windows form. does it support that?

This is an asp.net forum, not a windows forms forum. So I wasn't talking about windows forms. :)

As for whether it supports database-supplied values instead of xml files for the menu entries, you'll have to look that up. It's what I would do first if I had to code a solution like that. But I don't, and you do, so you can look it up and tell us about what you found. :)

|||

the problem here is not the datasource type but the logic on how to display second level navigation and third level navigation based on what is clicked. i.e. property or portfolio. I have seen lots of article which shows how to create a data driven menu using javascript downdown but i want second and third navigation to be static based on what is clicked( either property or portfolio).

please help

|||

I am thinking of alternative solution using 3 level datalist but its not working as there is no onclick property so that based on property link or portfolio link click i could display their childrens and based on their children click i could display their sub childs.

can anyone please help me?

|||

Hi! I used below method to implement 3 level navigation. but I now have a problem of maintaining the selected state of the item after postback.

when user logs in I need to somehow set the default page pointing to

Portfolio

Assets

Capex

and at the same time i need to show those three links active.

each page should go to differnt url with parameter. below are my codes. please help.

aspx

<asp:DataList ID="dlParent" runat="server" RepeatDirection="Horizontal" DataKeyField="MenuId" OnSelectedIndexChanged="parentselectedindexchanged" Font-Names="Trebuchet MS" Font-Size="Smaller" ForeColor="#404040">
<ItemTemplate>
<asp:LinkButton ID="lnkParent" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:DataList>
<asp:dataList id="dlChild" runat="server" RepeatDirection="Horizontal" DataKeyField="MenuId" OnSelectedIndexChanged="childselectedindexchanged" Font-Names="Trebuchet MS" Font-Size="Smaller">
<ItemTemplate>
<asp:LinkButton ID="lnkChild" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:dataList>
<asp:dataList id="dlSubChild" runat="server" RepeatDirection="Horizontal" Font-Names="Trebuchet MS" Font-Size="Smaller" >
<ItemTemplate>
<asp:LinkButton ID="lnkSubChild" runat="server" CommandName="select" Text='<%# DataBinder.Eval(Container, "DataItem.Text")%>'></asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="Silver" />
</asp:dataList>


code behind
--
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myDal As New clsDAL
Dim dsParent As DataSet
'Dim selParent As Integer = -1
'dlParent.SelectedIndex = selParent
If Not IsPostBack Then

dsParent = myDal.getSubMenuItems(0)

If Not dsParent Is Nothing Then
dlParent.DataSource = dsParent
dlParent.DataBind()
End If

End If
End Sub

Protected Function BuildUrl(ByVal field1 As Integer) As String
Dim baseUrl As String
baseUrl = "menu.aspx"
Return String.Format("{0}?navId={1}", baseUrl, field1)
End Function

Public Sub parentselectedindexchanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mydal As New clsDAL
Dim NavId As Integer
'Dim selChild As Integer = -1
'dlChild.SelectedIndex = selChild
Dim dsChild As New DataSet
Try
NavId = CInt(dlParent.DataKeys(dlParent.SelectedIndex))

dsChild = mydal.getSubMenuItems(NavId)
dlChild.DataSource = dsChild
dlChild.DataBind()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End Sub

Public Sub childselectedindexchanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim mydal As New clsDAL
Dim NavId As Integer
'Dim selSubChild As Integer = -1
'dlSubChild.SelectedIndex = selSubChild
Dim dsSubChild As New DataSet
Try
NavId = CInt(dlChild.DataKeys(dlChild.SelectedIndex))
dsSubChild = mydal.getSubMenuItems(NavId)
dlSubChild.DataSource = dsSubChild
dlSubChild.DataBind()
Catch ex As Exception
Response.Write(ex.ToString)
End Try
End Sub

|||

can someone at least point me to write direction?

|||

You could save the entire object in session cache and restore it with each postback.

Sorry, I don't know how to make it pre-open to a given location.

|||

could you please show me how you will do it as i have never used cache to store the datalist. a code snippet will be of great help.

cheers

No comments:

Post a Comment