v
Not logged inv
SearchAsk a QuestionReport an IssueMake a SuggestionMy Questions and Issues
Issue Details
Find By ID

How do I show or hide Add/Edit/Delete buttons depending on user?

Issue Details

Log in to Track Changes or Edit
Q139292
Question
Donn Edwards
Yes
Processed
Answered
.NET
ASPxGridView and Editors Suite
8.2
Windows XP
Microsoft Visual Studio 2008
9/11/2009 4:31:33 PM
-> Created by Donn Edwards 1 12/15/2008 10:37:11 AM

I have set up the ASPxGridview on a standard web page, and it is working wonderfully, but everyone visiting the page has full Add/Change/Delete permissions. I want to be able to restrict these permissions so that only specific users can see the New/Edit/Delete buttons, and everyone else has read-only viewing access.

I can't find any tutorial or example on how to enable/disable the buttons. Obviously the login stuff is a separate issue.

Please can you direct me to some sample code for enabling/disabling the buttons at run-time?

<- Reviewed by DevExpress Team 12/15/2008 11:17:24 AM
<- Processed (Answered) by DevExpress Team 12/15/2008 3:00:43 PM

Hello Donn,

To accomplish this task, you can update the Visible property of the corresponding GridViewCommandColumn buttons (DeleteButton, EditButton, etc), or hide a GridViewCommandColumn completely.
Refer to this sample code snippet:

[VB.NET]

For i As Integer = 0 To Me.ASPxGridView1.Columns.Count - 1
        If TypeOf Me.ASPxGridView1.Columns(i) Is GridViewCommandColumn Then
            CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).NewButton.Visible = False
            CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).UpdateButton.Visible = False
            CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).DeleteButton.Visible = False
            CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).EditButton.Visible = False
            Exit For
        End If
    Next i

Thank you,
Alex.

-> Reactivated by Donn Edwards 1 12/15/2008 8:57:14 PM

Thanks for such a prompt reply. It gives me great confidence in this product.

Where do I put this code? I tried the page's Form_Load and ASPxGridView1_Load events, but I'm getting

Compiler Error Message: BC30002: Type 'GridViewCommandColumn' is not defined.

error message, which I don't fully understand. I'm an experienced VB6/VBA programmer, but VB.NET and ASPX is still a little new, so please forgive these very basic questions ;-)

<- Processed (Answered) by DevExpress Team 12/16/2008 1:05:10 PM

Hello Donn,

Thanks for the update. It seems that you might need to use the Imports directive to add the DevExpress.Web.ASPxGridView namespace. For instance:

Imports DevExpress.Web.ASPxGridView
..
Let me know whether this helps.

Thank you,
Alex.

-> Reactivated by Donn Edwards 1 12/16/2008 2:17:17 PM

The code works, but I think I've attached it to the wrong event.

My entire page code looks like this:
>>>
Imports System.Web.DynamicData
Imports DevExpress.Web.ASPxGridView

Partial Class List
    Inherits System.Web.UI.Page

    Protected blnAddYN As Boolean
    Protected blnChgYN As Boolean
    Protected blnZoomYN As Boolean
    Protected blnDelYN As Boolean

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        blnAddYN = False
        blnChgYN = False
        blnDelYN = False
        blnZoomYN = False
    End Sub

    Protected Sub ASPxGridView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ASPxGridView1.Load
        For i As Integer = 0 To Me.ASPxGridView1.Columns.Count - 1
            If TypeOf Me.ASPxGridView1.Columns(i) Is GridViewCommandColumn Then
                CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).NewButton.Visible = blnAddYN
                CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).UpdateButton.Visible = blnChgYN
                CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).DeleteButton.Visible = blnDelYN
                CType(Me.ASPxGridView1.Columns(i), GridViewCommandColumn).EditButton.Visible = blnZoomYN
                Exit For
            End If
        Next i
    End Sub
End Class
<<<

If I set blnZoomYN to True, then the "Edit" button appears correctly, but when I click to edit a record, the "Update" button appears. Should I attach this code to a different event as well?

<- Processed (Answered) by DevExpress Team 12/16/2008 2:44:51 PM

Hi Donn,

Please move the ASPxGridView1_Load event handler code to the Page_Load event handler.
When modifying ASPxGridView properties ar runtime, you should do this on each postback.
Let me know how this goes.

Thanks,
Alex.

<- Processed (Customer Closed) by Donn Edwards 9/11/2009 4:31:33 PM

sorted. Thanks!

Log in to Track Changes or Edit

Peer-to-Peer Discussion in DevExpress Forums

No discussion on this article has been started yet.

Please login to start discussion.

v
v
Search
Searching Tips