views:

258

answers:

1

Hello All,

I am using c#.net

I have a repeater and a ObjectDataSource (ObjectDataSource is created within the code behind).

Within the repeater are two buttons (edit/delete). I need to system to either hide/remove these buttons if the user doesn’t have permissions to edit/delete.

Repeater Code

              <ItemTemplate>
                  <tr class="tRow left">
                    <td>                      
                      <asp:Button ID="editClick" OnCommand="EditClick" runat="server" Text="Edit" />
                      <asp:Button ID="deleteClick" OnCommand="DeleteClick" runat="server" Text="Delete/Cancel" />
                    </td>
                    <td><%#Eval("bookingID")%></td>
                  </tr>
     </ItemTemplate>

I thought I could add an if statement to the repeater however the userRepository is a class and I dont want to be accessing a class within my source code. Is there another way of doing it?

          <ItemTemplate>
              <tr class="tRow left">
                <td>                      
                  <%if (!userRepository.GetPermission("xxxxx"))
                  {%>
                    <asp:Button ID="editClick" OnCommand="EditClick" runat="server" Text="Edit" />
                    <asp:Button ID="deleteClick" OnCommand="DeleteClick" runat="server" Text="Delete/Cancel" />
           <%}%>
                </td>
                <td><%#Eval("bookingID")%></td>

Thanks in advance for any help.

Clare

+3  A: 

To neaten things up in your aspx file you could add a property such as this to your code-behind:

public bool HasEditPermission
{
    get { return !userRepository.GetPermission("xxxxx"); }
}

then in your aspx page you could do:

<ItemTemplate>
  <tr class="tRow left">
    <td>                      
      <asp:Button ID="editClick" Enabled="<%#HasEditPermission%>" OnCommand="EditClick" runat="server" Text="Edit" />
      <asp:Button ID="deleteClick" Enabled="<%#HasEditPermission%>" OnCommand="DeleteClick" runat="server" Text="Delete/Cancel" />
    </td>
    ....
mdresser