How to disable in Runtime deleting records in a Gridview

Simon 426 Reputation points
2025-03-03T22:48:25.9166667+00:00

i am working on a aspx page and vb.net

how can i disable deleteing rows for some user from a gridview

looking forward

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,031 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 57,131 Reputation points
    2025-03-03T23:10:56.17+00:00

    There is insufficient information here to fully address your question. Can you please provide us clarification on exactly what you're trying to accomplish? Information on what you've already tried and screenshots, if appropriate, would be useful.

    Based upon the statement "disable deleting rows for some users" it sounds like you want to enable permissions in your app such that some users can delete records while others cannot. Is this correct?

    If so then the first question is how are you authenticating your users? The follow up question is how you determine what users can and cannot delete records? If you haven't implemented any of this logic yet then you're going to have to work on that part first.

    On the UX side you also need to decide how you want to bubble this up. Presumably you have a "delete" button or something in your UX and ideally some sort of confirmation UX when it is clicked. The best solution is for the UX to remove the delete UX when the user doesn't have the permission. This can be handled by your rendering code not showing the button if the user doesn't have permissions. But it depends on how you are rendering the grid. For a more traditional approach refer to something like this. Of course the Visible button is a somewhat clean approach but if you don't trust users then you probably should ensure it doesn't render at all. An alternative, as discussed later in the post, is to handle this at row binding. It'll depend on whether you're using codebehind or eventing to manage your GridView, you can go either way. If you're populating the data on the client side then that would change things as well.

    But, again, this is dependent on how you authenticate your users and how you determine whether they have permissions or not. At a minimum, if we assume you are using traditional authentication and you have already hooked into the HttpContext.User object to manage your user information, you'd need to look at the "permissions" of the user and determine whether they have the necessary rights or not. If you're using a claims-based approach then it might be a claim or role the user is in. Again, depends on how you're going to implement this on your security side.

    Remember that a user can generate a server-side request irrelevant of the UX so ultimately your server side code that handles the request to delete a record should also ensure the user is allowed to perform the delete. This server-side check should always be done irrelevant of what the UX does. If you have implemented a web API solution then this can be handled on the API side, otherwise the codebehind for the delete button should validate the permissions.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.