Can somebody explain to me how to hide a repeater column based on the user privileges.
Say I have:
<asp:Repeater ID="repeater" runat="server>
<HeaderTemplate>
<table id="table_id">
<tr>
<th>Name</th>
<th>Secret Info</th>
<tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' /></td>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("SecretInfo") %>' /></td>
<tr>
<ItemTemplate>
<AlternatingItemTemplate>
<tr>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' /></td>
<td><asp:Label ID="Label1" runat="server" Text='<%# Eval("SecretInfo") %>' /></td>
<tr>
<AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
How would I only display the 'Secret Info' column to logged on users?
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):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.aspxSo something like:
You could do something like the following:
Where IsUserLoggedOn is some function that returns a boolean that is true if the user is logged on