Hi smile,
Refer below example.
HTML
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
table { border: 1px solid #ccc; border-collapse: collapse; background-color: #fff; }
table th { background-color: #B8DBFD; color: #333; font-weight: bold; }
table th, table td { padding: 5px; border: 1px solid #ccc; }
table, table table td { border: 0px solid #ccc; }
.main_menu, .main_menu:hover { width: 100px; background-color: #A6A6A6; color: #ffffff; text-align: center; height: 30px; line-height: 30px; margin-right: 5px; }
.main_menu:hover { background-color: #ccc; }
.level_menu, .level_menu:hover { width: 110px; background-color: #A6A6A6; color: #ffffff; text-align: center; height: 30px; line-height: 30px; margin-top: 5px; }
.level_menu:hover { background-color: #ccc; }
.selected, .selected:hover { background-color: #A6A6A6 !important; color: #fff; }
</style>
<table>
<tr>
<td>Username</td>
<td>
<asp:TextBox runat="server" ID="txtUserName" Text="User3" />
</td>
</tr>
<tr>
<td>Password</td>
<td>
<asp:TextBox runat="server" ID="txtPassword" Text="abc@123" TextMode="Password" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button Text="Login" runat="server" OnClick="OnLogin" />
</td>
</tr>
</table>
<hr />
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="main_menu" />
<asp:MenuItemStyle CssClass="level_menu" />
</LevelMenuItemStyles>
<StaticSelectedStyle CssClass="selected" />
</asp:Menu>
Namespaces
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void OnLogin(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[] {
new DataColumn("UserID"),
new DataColumn("UserName"),
new DataColumn("UserPass"),
new DataColumn("ModuleA"),
new DataColumn("ModuleB"),
new DataColumn("ModuleC"),
new DataColumn("ModuleD"),
new DataColumn("ModuleE"),
new DataColumn("ModuleF"),
new DataColumn("ModuleG")
});
dt.Rows.Add(1, "User1", "abc@123", true, false, false, true, false, false, true);
dt.Rows.Add(2, "User2", "abc@123", false, true, true, false, true, false, false);
dt.Rows.Add(3, "User3", "abc@123", true, true, true, true, true, true, true);
DataRow dr = dt.AsEnumerable()
.Where(x => x["UserName"].ToString() == txtUserName.Text && x["UserPass"].ToString() == txtPassword.Text).FirstOrDefault();
Menu1.Items.Clear();
for (int i = 3; i < dr.ItemArray.Length; i++)
{
if (Convert.ToBoolean(dr.ItemArray[i].ToString()))
{
string menuName = string.Empty;
switch (dt.Columns[i].ColumnName)
{
case "ModuleA":
menuName = "Module A";
break;
case "ModuleB":
menuName = "Module B";
break;
case "ModuleC":
menuName = "Module C";
break;
case "ModuleD":
menuName = "Module D";
break;
case "ModuleE":
menuName = "Module E";
break;
case "ModuleF":
menuName = "Module F";
break;
case "ModuleG":
menuName = "Module G";
break;
}
Menu1.Items.Add(new MenuItem { Value = menuName, Text = menuName });
}
}
}
VB.Net
Protected Sub OnLogin(ByVal sender As Object, ByVal e As EventArgs)
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {
New DataColumn("UserID"),
New DataColumn("UserName"),
New DataColumn("UserPass"),
New DataColumn("ModuleA"),
New DataColumn("ModuleB"),
New DataColumn("ModuleC"),
New DataColumn("ModuleD"),
New DataColumn("ModuleE"),
New DataColumn("ModuleF"),
New DataColumn("ModuleG")})
dt.Rows.Add(1, "User1", "abc@123", True, False, False, True, False, False, True)
dt.Rows.Add(2, "User2", "abc@123", False, True, True, False, True, False, False)
dt.Rows.Add(3, "User3", "abc@123", True, True, True, True, True, True, True)
Dim dr As DataRow = dt.AsEnumerable() _
.Where(Function(x) x("UserName").ToString() = txtUserName.Text AndAlso x("UserPass").ToString() = txtPassword.Text).FirstOrDefault()
Menu1.Items.Clear()
For i As Integer = 3 To dr.ItemArray.Length - 1
If Convert.ToBoolean(dr.ItemArray(i).ToString()) Then
Dim menuName As String = String.Empty
Select Case dt.Columns(i).ColumnName
Case "ModuleA"
menuName = "Module A"
Case "ModuleB"
menuName = "Module B"
Case "ModuleC"
menuName = "Module C"
Case "ModuleD"
menuName = "Module D"
Case "ModuleE"
menuName = "Module E"
Case "ModuleF"
menuName = "Module F"
Case "ModuleG"
menuName = "Module G"
End Select
Menu1.Items.Add(New MenuItem With {
.Value = menuName,
.Text = menuName
})
End If
Next
End Sub
Screenshot