我尝试按用户类型限制dropdownlist但语法错误 [英] I try to restrict dropdownlist by user type but syntax error
问题描述
我试图限制不同类型的用户。至于 superadmin 可以访问所有下拉列表,培训师只能访问某些下拉列表和用户。但不幸的是我的代码返回语法错误。请帮我解决这个问题。
我尝试过:
ASP代码:
< asp:DropDownList ID =deptDropDownListrunat =serverAppendDataBoundItems =TrueAutoPostBack =True
DataValueField =deptName Height =22pxWidth =132px>
< asp:ListItem Value => - 选择选项 -
< asp: ListItem Value =Training> Training Module
< asp:ListItem Value =MFG Module> MFG Module
< asp:ListItem Value =SelfLearning >员工培训记录
< asp:ListItem Value =Others> Others
< asp:ListItem Value =InterviewTrackingSystem>面试跟踪系统
&l t; asp:ListItem Value =ListOfEmployee>员工名单
代码背后:
If(reader(emp_type)。ToString()=superadmin和reader(trainer_AccessModule)。ToString())然后
(deptDropDownList.SelectedValue = 训练.Visible)=True
(deptDropDownList.SelectedValue =MFG模块.Visible)=True
(deptDropDownList.SelectedValue =SelfLearning .Visible)=True
(deptDropDownList.SelectedValue =Others.Visible)=True
(deptDropDownList.SelectedValue =InterviewTrackingSystem.Visible)= 真实
(deptDropDownList.SelectedValue =ListOfEmployee.Visible)=True
等等
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
推荐答案
我不确定你在尝试什么o实现。您的描述仍然令人困惑。但是,如果您只想根据某些用户角色查看DropDownList
中的特定项目,那么您可以执行以下操作:
首先,您必须清除HTML标记(.aspx)中DropDown中的静态项目,例如:
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 yourDropDownList
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: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:我不是一个VB人,只是使用转换将C#转换为VB.NET等价物
PS: I'm not a VB guy and just used a convert to translate C# to it's VB.NET equivalent
这篇关于我尝试按用户类型限制dropdownlist但语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!