I have a repeater, on its item_command event i am binding another repeater. And i want to show data according to role in the second repeater. For it i want to hide and show some column according to role of users. how can we do it using code behind. Thanks in advance. My code is
<table id="table1" class="yui" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>
<a href='#' title="Click Header to Sort">EmpID #</a>
</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="Repaddressorbbl" runat="server" OnItemCommand="Repaddressorbbl_ItemCommand">
<ItemTemplate>
<tr id="gh" style="cursor: pointer" onclick="Select(this);">
<td style="text-align: center;">
<%#Eval("empid")%>
</td>
<td>
<asp:LinkButton ID="lknumber" runat="server" Text="Edit" CommandName="searchbybbloraddress" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
<tfoot>
</tfoot>
</table>
protected void Repaddressorbbl_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "searchbybbloraddress")
{
bind_rep2();
}
}
If you want to databind the second repeater from the ItemCommand in your code behind you have two options.
You could modify the dataset you set as the DataSource of the second repeater and set the sensitive data to an empty string or **.
The other option you have is add a IsVisibleToUser boolean property to your dataset and in your second repeater bind the Visible property to this property.
You can easily modify the data that is given to your DataSource by using a Linq query that produces an anonymous object.
Something like:
Repeater2.DataSource = from d in MyData
select new
{
FirstName = d.FirstName,
LastName = d.LastName,
Salary = d.Salary,
IsVisibleToUser = CurrentUser.IsInRole(...)
}