我正在尝试为不同的用户角色提供不同的选项。这是我的代码:
Private Function GetApprovedBy() As String
If User.Identity.Name = "officer" Then
Return "Approved by Officer"
ElseIf User.Identity.Name = "manager" Then
Return "Approved by Manager"
Else
Return String.Empty
End If
End Function
然后在我的gridview模板中,我有:
<EditItemTemplate>
<asp:DropDownList ID="ApprovalEdit" runat="server">
<asp:ListItem>Rejected</asp:ListItem>
<asp:ListItem Text=<%= GetApprovedBy() %>></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
当我运行页面时,我得到
"Literal content ('<asp:ListItem Text=') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection'."
有没有其他方法可以实现这一目标?最好没有数据库。
提前致谢!!
编辑:我也试过
<asp:ListItem><%= GetApprovedBy() %></asp:ListItem>
失败并出现错误“此上下文不支持代码块”