repeater conditional view with no data logic
on my repeater i builed a table and want to show a colum just for user that is in role admin.
i need to remove the column in the HeaderTemplate and in ItemTemplate. i could use data logic and add a db column that will be boolean, but then i need to send to the SP the user role.<asp:Repeater ID="TemplatesList" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>
#
</th>
<th>
Title
</th>
<th>
Subject
</th>
<th>
</th>
<th>
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("ET_ID")%>
</td>
<td>
<%# Eval("ET_Title")%>
</td>
<td>
<%# Eval("ET_Su开发者_JAVA百科bject")%>
</td>
<td>
<a href="<%# VirtualPathUtility.ToAbsolute("~/Admin/EmailsTemplates/Delete.aspx?id="+Eval("ET_ID").ToString())%>">
Delete</a>
</td>
<td>
<a href="<%# VirtualPathUtility.ToAbsolute("~/Admin/EmailsTemplates/Edit.aspx?id="+Eval("ET_ID").ToString())%>">
Edit</a>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
If you just want to hide the column than you can use LoginView control which can select content based on roles:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.loginview.aspx
it should work within templates
or you can use inline scripting, something like this:
<% if (User.IsInRole("Admin")) { %>
<td> xxx </td>
<% } %>
精彩评论