Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any one can guide and help in this case to create a dynamically left drop down menu with css and database and asp.net

What I have tried:

i never tried but i want to create and link it dabatase for create rule to users and admin access menu
Posted
Updated 25-Sep-19 9:56am

What you want to do some research on is going to be Role Based Authorization. What this topic covers is users and their respective roles, and the associated permissions for what they can do.

The methods here maybe application specific for the NetCore 3.0, but the overall functional flow is going to be the same
Role-based authorization in ASP.NET Core | Microsoft Docs[^]


Now this may be overkill for a simple project, where you just want to have one login (for admin) and everyone is just a guest. In this case what you could do is just have the login and authentication scheme, and if they are logged in (checked via a session variable or cookie) then you display an additional chunk of the menu.
 
Share this answer
 
Quote:
in this case
In which case?

Dynamic menus can be created easily, you can use a query that extracts all the menu records from the database table, and then generate a menu based on that. For example, here is a sample table,
| MenuId | MenuPlacing |
|--------|-------------|
| 1      | Navigation  |
| 2      | Footer      | 
| 3      | Post        |
You can see that instead of creating menus, I created a list that will help me select the type of menu I want. Now this can be used to further add the menu items,
| MenuItemId | MenuId | Heading | Tooltip     | Hyperlink  | Active |
|------------|--------|---------|-------------|------------|--------|
| 1          | 1      | Home    | Home page   | "/"        | true   |
| 2          | 1      | About   | Our company | "/about"   | true   |
| 3          | 1      | Contact | Reach us    | "/contact" | true   |
| 4          | 1      | Sales   | Sales team  | "/sales"   | true   |
These kind of tables can help you use the search query in SQL and fetch the records for a particular menu. Then you can render the data on the HTML using foreach statements, suppose after the response you have a variable that holds the output of the MenuItem table. You can iterate over the result and render a list,
XML
<ul>
    @foreach (var menuItem in menuItemList) {
        if(menuItem.Active) {
            <li>
                 <a href="@menuItem.Hyperlink" title="@menuItem.Tooltip">
                     @menuItem.Heading
                 </a>
            </li>
        }
    }
</ul>
This will setup a list of the items, that you selected from your database.

You can check my article on SQL Server connections with C# language, How to connect SQL Database to your C# program, beginner's tutorial[^].
 
Share this answer
 
Comments
MadMyche 25-Sep-19 16:24pm    
I believe the O/P wants the menu to change based on login: for create rule to users and admin access menu
irfanansari 26-Sep-19 4:28am    
sir this is i think MVC sir can you tell some guide in simple asp.net please and you told good way just i need in this also sub menew as
| MenuItemId | MenuId | Heading | Tooltip | Hyperlink | Active |
|------------|--------|---------|-------------|------------|--------|
| 1 | 1 | Home | Home page | "/" | true |
| 2 | 1 | About | Our company | "/about" | true |
| 3 | 1 | Contact | Reach us | "/contact" | true |
| 4 | 1 | Sales | Sales team | "/sales" | true |
| 5 | 4 |"cash sale|cash sale |"/cash sale"| true |

then sale is main menu and cash sale is sub menu
Afzaal Ahmad Zeeshan 26-Sep-19 10:25am    
Using the same concept, you just need to perform a SQL query to get the menu and then render it as I have shown using a foreach loop.

You should read my article to learn about the SQL query and C# code, and use the foreach to render the output. Try and show the code that you have used.
irfanansari 27-Sep-19 8:00am    
sir i already create a database and querry for select * from Menew and table is mine as bellow
SR_NO Menew Page_link MenuId Active
1 home home.aspx null TRUE
2 about about.aspx null TRUE
3 sale null TRUE
4 cash sale cash.aspx 3 TRUE
5 installemnt sale HP.aspx 3 TRUE
6 contact us contactus.aspx null TRUE
Afzaal Ahmad Zeeshan 27-Sep-19 16:38pm    
And?

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