This is a migrated thread and some comments may be shown as answers.

Hiding and displaying the toolbar

3 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Brendan Vogt
Top achievements
Rank 1
Brendan Vogt asked on 30 Sep 2010, 02:23 PM
Hi,

I am using a grid on my application to display a list of attachments.  Every one can see this list.  Only an administrator is allowed to add new attachments, and for this add button I would use the following code to display this add button:

.ToolBar(commands => commands.Custom().Text("Add New Attachment").Action("CreateAttachment", "Application"))

Now the tricky part is that only the administrator can see this button, the rest cannot see it.  I have a base controller class that determines if the logged on user is an administator or not.  I also created a helper class for this to be used in the view like:

<%
if (Html.IsAdministrator()) {} %>

How would I put an if in my grid to display the toolbar if it is an administrator and to hide it if it is not an administrator?  Is this in any way possible?

Thanks
Brendan

3 Answers, 1 is accepted

Sort by
0
Uma
Top achievements
Rank 1
answered on 30 Sep 2010, 09:21 PM
Hi Brendan,
I'm not sure whether we can hide/display the toolbar based on the condition, but there is a work around to achieve this. Have two grids, one with Toolbar and one without, based on the user role display the respective grid. I know this is not a good solution but for time being you can acheive the functionality

Regards,
Uma
0
Brendan Vogt
Top achievements
Rank 1
answered on 01 Oct 2010, 11:34 AM
Hi,

I can do it this way but it is going to be a lot of code displaying the 2 grids twice.  I was thinking more in the line as below but I can't get it to work:

<% if (Html.IsAdministrator()) %>
<% { %>
<% .ToolBar(commands => commands.Custom().Text("Add Attachment").Action("CreateAttachment", "Application")) %>
<% } %>
0
nachid
Top achievements
Rank 1
answered on 01 Oct 2010, 12:56 PM
What If you use HtmlAttributes to add to your button a trivial attribute
Use JQuery to hide/show this button according to this attribute value
Tags
Grid
Asked by
Brendan Vogt
Top achievements
Rank 1
Answers by
Uma
Top achievements
Rank 1
Brendan Vogt
Top achievements
Rank 1
nachid
Top achievements
Rank 1
Share this question
or