如何在ASP.NET中动态地看到虚假的模板字段 [英] How to visible false Template field dynamically in asp.net

查看:49
本文介绍了如何在ASP.NET中动态地看到虚假的模板字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在系统中扮演两个角色,因为两个我都使用同一个页面,为此我创建了UserControl.
对于管理员
我想在模板字段中显示编辑或删除链接.
致老师
我只想显示编辑链接.

在aspx.cs页面中

I have two role for my system.For both i am using the same page.I created UserControl for that.
For admin
I want to display edit or delete link in template field.
For Teacher
I want to display only edit link.

In aspx.cs page
How to find Template field and how to make visible false to it without using column number for teacher?

推荐答案

您始终可以将Visible 属性绑定到方法上您的.cs文件.

但您也可以使用如下内联代码:
You can always bind the Visible property to a method on your .cs file.

But you can also use inline code like this:
<%
if (IsVisible())
{%>
   <asp:LinkButton ID="mylink" Text="Your link text"runat="server"> </asp:LinkButton>
<% }%>




您可以基于IsVisible函数上的逻辑来限制任何asp.net或html代码的呈现.可以这样实现:




You can condition the rendering of any asp.net or html code based on the logic on that IsVisible function. That could be implemented like this:

protected bool IsVisible()
{
     return Roles.IsUserInRole("admin");
}



您将用最终代码替换该函数,在这种情况下,因为这是一条简单的返回行,但是,这将取决于您的后端代码.

希望对您有所帮助.



You replace the function with the final code, in this case because is a simple return line, but well, that will depend on your back-end code.

Hope it helps.


这篇关于如何在ASP.NET中动态地看到虚假的模板字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆