我有一个用于保存链接和图像按钮的表,用于将用户链接到网站上的其他页面。我想根据使用的权限隐藏其中一些行。现在我有:
// Disable buttons if user does not have admin security level
if (Session["SecurityLevel"] != "A")
{
linkbtnNewEmployee.Visible = false;
imgbtnNewEmployee.Visible = false;
linkbtnViewUserActivity.Visible = false;
imgbtnViewUserActivity.Visible = false;
linkbtnEditEmployees.Visible = false;
imgbtnEditEmployees.Visible = false;
linkbtnManageUsers.Visible = false;
imgbtnManageUsers.Visible = false;
}
将隐藏链接和按钮,但表行仍然存在。所以链接之间有一行或两行空格。我试过命名行并使用“rowToHide.style.display ='none';”命令不起作用,因为它无法识别行。行id在源代码中显示正常,我在命令中使用相同的ID。有什么建议?谢谢你的帮助!
答案 0 :(得分:1)
在标记中添加<tr>
和runat="server"
标记的ID,如下所示:
<tr id="rowToHide" runat="server>
<!-- Contents here -->
</tr>
在代码中将visible属性设置为false,如下所示:
// Disable buttons if user does not have admin security level
if (Session["SecurityLevel"] != "A")
{
rowToHide.Visible = false;
linkbtnNewEmployee.Visible = false;
imgbtnNewEmployee.Visible = false;
linkbtnViewUserActivity.Visible = false;
imgbtnViewUserActivity.Visible = false;
linkbtnEditEmployees.Visible = false;
imgbtnEditEmployees.Visible = false;
linkbtnManageUsers.Visible = false;
imgbtnManageUsers.Visible = false;
}