Click here to Skip to main content
15,909,518 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi,
i want to show different menu for different users but dont show menu

for example a users show only home page in menu
b users show about page and home page in menu
c user show only about page in menu


I have 3 tables in databases

1. Kullanıcılar[in english users] (username(PK) ve userpassword fields)

2. Menuler (MenuId(PK),SayfaAdi ve SayfaLink[In english PageLink] fields)

3. KullaniciMenu(username ve menuid fields)
---------------
C#
public class MenuBilgi
{
    private string sayfaAdi;
    private string sayfaLink;

    public string SayfaLink
    {
        get { return sayfaLink; }
        set { sayfaLink = value; }
    }
    public string SayfaAdi
    {
        get { return sayfaAdi; }
        set { sayfaAdi = value; }
    }
    public MenuBilgi(string sayfaAdi, string sayfaLink)
    {
        this.sayfaAdi = sayfaAdi;
        this.sayfaLink = sayfaLink;
    }
}
--------------------------------------------
aLTER proc [dbo].[MenuGetir]
(
@Username nvarchar(15)
)
as
select SayfaAdi,SayfaLink from Menuler inner join KullaniciMenu on Menuler.MenuId=Kullanici.MenuId where KullaniciMenu.Username=@Username
------------------------------------
public partial class SiteMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

        SqlParameter[] paramdizi = new SqlParameter[1]

            {
               new SqlParameter("@UserName",SqlDbType.NVarChar)
            };

        paramdizi[0].Value = Session["Username"];

        Baglanti baglanti = new Baglanti();

        SqlDataReader dr = baglanti.ExecuteReader("MenuGetir", CommandType.StoredProcedure, paramdizi);

        List<MenuBilgi> liste = new List<MenuBilgi>();

        while (dr.Read())
        {
            MenuBilgi bilgi = new MenuBilgi(dr.GetString(0), dr.GetString(1));
            liste.Add(bilgi);
        }

        NavigationMenu.DataSource = liste; NavigationMenu.DataBind();
    }
}

-------------------------------------
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                    <Items>
                        <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
                    </Items>

               </asp:Menu>

But navigationmenu.datasource=liste; >>> THİS ERROR MESAJ: HierrarhicalDataBoundControl only accept datasources that implement HierarchicalDataSource or HierarchicalEnumerable.

help pls
Posted
Updated 15-Jan-13 7:32am
v2
Comments
Sergey Alexandrovich Kryukov 9-Apr-13 14:20pm    
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

You need to set your datasource with any implemented by IHierarchyData.
Check this article, i hope it will help you.
Implementing IHierarchy Support Into Your Custom Collections[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900