Can somebody explain to me how to hide a repeater column based on the user privileges.
Say I have:
You can render the <td>
elements conditionally. This simplified example presumes you have a Page-level property that indicates whether or not the user is logged on (you'll want to do the same thing in the header template):
<asp:Repeater ID="repeater" runat="server>
<ItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' /></td>
<% if (this.UserIsLoggedOn) { %>
<td><asp:Label ID="Label2" runat="server" Text='<%# Eval("SecretInfo") %>' /></td>
<% } %>
<tr>
</ItemTemplate>
</asp:Repeater>
You could do something like the following:
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("SecretInfo") %>' Visible='<%# IsUserLoggedOn() %>' /></td>
Where IsUserLoggedOn is some function that returns a boolean that is true if the user is logged on
You can use the loginview
control which can display controls based on role (including anonymous vs authenticated). You can find a guide here: http://weblogs.asp.net/sukumarraju/archive/2010/07/28/role-based-authorization-using-loginview-control.aspx
So something like:
<asp:Repeater ID="repeater" runat="server>
<HeaderTemplate>
<table id="table_id">
<tr>
<th>Name</th>
<asp:LoginView ID="lvwHeader" runat="server">
<LoggedInTemplate>
<th>Secret Info</th>
</LoggedInTemplate>
</asp:LoginView>
<tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' /></td>
<asp:LoginView ID="lvwItem" runat="server">
<LoggedInTemplate>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("SecretInfo") %>' /></td>
</LoggedInTemplate>
</asp:LoginView>
<tr>
<ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' /></td>
<asp:LoginView ID="lvwItem" runat="server">
<LoggedInTemplate>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("SecretInfo") %>' /></td>
</LoggedInTemplate>
</asp:LoginView>
<tr>
<AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>