Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I try to make restriction for different type of user. As for superadmin can access all dropdownlist, for trainer only can access certain dropdownlist and for user too. But unfortunately my code return syntax error. Please help me to solve this problem.

What I have tried:

ASP Code:
<asp:DropDownList ID="deptDropDownList" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
DataValueField="deptName" Height="22px" Width="132px">
<asp:ListItem Value="">-- Select Option --
<asp:ListItem Value="Training">Training Module
<asp:ListItem Value="MFG Module">MFG Module
<asp:ListItem Value="SelfLearning">Employee Training Record
<asp:ListItem Value="Others">Others
<asp:ListItem Value="InterviewTrackingSystem">Interview Tracking System
<asp:ListItem Value="ListOfEmployee">List Of Employee


Behind Code :

If (reader("emp_type").ToString() = "superadmin" And reader("trainer_AccessModule").ToString()) Then
(deptDropDownList.SelectedValue = "Training".Visible) = "True"
(deptDropDownList.SelectedValue = "MFG Module".Visible) = "True"
(deptDropDownList.SelectedValue = "SelfLearning".Visible) = "True"
(deptDropDownList.SelectedValue = "Others".Visible) = "True"
(deptDropDownList.SelectedValue = "InterviewTrackingSystem".Visible) = "True"
(deptDropDownList.SelectedValue = "ListOfEmployee".Visible) = "True"

And so on
Posted
Updated 17-Aug-18 3:43am
Comments
F-ES Sitecore 17-Aug-18 4:09am    
(deptDropDownList.SelectedValue = "Training".Visible) = "True"

This makes no sense, what is it you're trying to do? "Training" is a string, it doesn't have a "Visible" property, and if you did set SelectedValue to something the result of that wouldn't be "True" either as that is another string.
Member 13949827 17-Aug-18 4:54am    
F-ES Sitecore thank you for your answer. Can you suggest me how to fix it? Is there any way?
F-ES Sitecore 17-Aug-18 4:56am    
You'll have to explain what it is you're trying to do.
Member 13949827 17-Aug-18 5:03am    
I try to make restriction for every dropdownlist. For example dropdownlist for value = "Training", all user can access. But for dropdownlist value = "List Of Employee" only superadmin can access. It will grey out for Trainer & User.

1 solution

I'm not exactly sure what you are trying to achieve. Your description is still confusing. However, if you want to only see specific items in your DropDownList based on some user roles, then you can do something like this:

First, you have to clear out the static items from your DropDown in your HTML markup (.aspx) like:
ASP.NET
<asp:DropDownList ID="deptDropDownList" runat="server" AppendDataBoundItems="False" AutoPostBack="True" /> 



C#
C#
var role = reader["emp_type"].ToString().ToLower();

deptDropDownList.Items.Clear();
if(role.Equals("superadmin")){
      	deptDropDownList.Items.Add(new ListItem("Training", "Training"));
	deptDropDownList.Items.Add(new ListItem("MFGModule", "MFG Module"));
	deptDropDownList.Items.Add(new ListItem("SelfLearning", "Self Learning"));
	deptDropDownList.Items.Add(new ListItem("InterviewTrackingSystem", "Interview Tracking System"));
	deptDropDownList.Items.Add(new ListItem("Others", "Others"));
	deptDropDownList.Items.Add(new ListItem("ListOfEmployee", "List Of Employee"));
}
else if (role.Equals("trainer")){
	deptDropDownList.Items.Add(new ListItem("Training", "Training"));
}
else if (role.Equals("whatever")){
     //add appropriate items to your DropDownList
}


VB
VB
Dim role As var = reader("emp_type").ToString.ToLower
deptDropDownList.Items.Clear
If role.Equals("superadmin") Then
    deptDropDownList.Items.Add(New ListItem("Training", "Training"))
    deptDropDownList.Items.Add(New ListItem("MFGModule", "MFG Module"))
    deptDropDownList.Items.Add(New ListItem("SelfLearning", "Self Learning"))
    deptDropDownList.Items.Add(New ListItem("InterviewTrackingSystem", "Interview Tracking System"))
    deptDropDownList.Items.Add(New ListItem("Others", "Others"))
    deptDropDownList.Items.Add(New ListItem("ListOfEmployee", "List Of Employee"))
ElseIf role.Equals("trainer") Then
    deptDropDownList.Items.Add(New ListItem("Training", "Training"))
ElseIf role.Equals("whatever") Then
    'add appropriate items to your DropDownList
End If


PS: I'm not a VB guy and just used a convert to translate C# to it's VB.NET equivalent
 
Share this answer
 
Comments
Member 13949827 19-Aug-18 22:39pm    
Thank you Vincent Maverick. The code works!!
Vincent Maverick Durano 20-Aug-18 9:06am    
My apology for a late response. I just got back from vacation. I'm glad to be of help.

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