Avatar of Cluskitt
Cluskitt
Flag for Portugal asked on

Best control for code-behind bound data

I want to access data from my table, but since there are a few runtime parameters, I'll be defining the datasource (most likely with SqlDataAdapter, unless a better option exists) in the code behind file. I have a role for each of the 4 SQL commands (CRUD). So, if a user has a "ReadRole", they can access the page. If they have a "UpdateRole" they can edit, etc. A user can have all 4, or most combinations of them ("ReadRole" is the minimum required).

Now, I want to show my data in an "Access-like" way. That is, one record at a time, with Next/Previous/First/Last controls. There has to be a possibility of limiting the buttons (delete/edit/new) depending on the roles.  Also, it is required that one of the fields is a calendar control (or similar).

What is the best control I can use to do this? I have no problem in doing most of the code, if that's the most effective way to accomplish what I require. However, it is essential that I can have absolute control over who does what.
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Nasir Razzaq

8/22/2022 - Mon
Rick

Nasir Razzaq

If the requirement is to navigate through the records one by one, look at the formview control.

This one comes with builtin navigation

http://www.codeproject.com/KB/webforms/FVPageTemplate.aspx
Cluskitt

ASKER
I am not sure how to limit access to edit/delete/new buttons with a gridview. I had already looked into it, and saw that I could set it to show one at a time, but the roles part was what stumped me.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Cluskitt

ASKER
Ditto for the formview. If it weren't for the different roles, it would be pretty simple.
Nasir Razzaq

You can show the different links based on the role. For example, you can disable/hide the update link/button if the user does not have that role.
Cluskitt

ASKER
CodeCruiser, checking your link, it seems that pretty much everything is created from scratch in the code behind. That's hardly any code left from the original FormView. I know I can do what I want by creating the fields, binding them to an SqlDataAdapter and using my own code in the new/edit/delete buttons (which I'll have to do anyway, to insert a record in the audit table).

It seems to me that the easiest way, though, would be to use a gridview control set to one record at a time. But with a way to limit functions depending on the roles. And that is what I can't seem to accomplish. Any ideas regarding that?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Cluskitt

ASKER
I was thinking of something like:

1) On the rowdeleting event, checking for the appropriate role and cancelling if the user doesn't have it.

Or, preferably:
2) On page load, setting the gridview update/delete/new permissions.

Wouldn't that be a simple and efficient approach? Especially seeing as I already have to access all those events for code behind and for sending new records to an audit table?
Nasir Razzaq

Yes you can take that route.
Cluskitt

ASKER
Well, that is exactly the point where I'm getting stumped. How can I define the delete/new/edit permissions at runtime? Or, how can I cancel a delete/etc when it's being raised. So, preferably, something like:

If Not User.IsInRoles("ThisRole") Then
  Griview1.ShowDeleteButton = False
End If

Or, on rowdeleting:

If Not User.IsInRoles("ThisRole") Then
  Griview1.CancelDelete = True
End If

But I can't find the appropriate properties/methods to accomplish this. The ones I used are obviously bogus and more like pseudocode. But it seems that something like that should exist. I just can't find it :P
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Cluskitt

ASKER
Ok, I was trying to use a GridView (which means that all I had was a CommandField and I couldn't use that there). I switched to a FormView. Your solution works perfectly. However, there's only a small navigation problem. I see one record at a time, but instead of next/previous/first/last, I see link with 1,2,3,4,etc...

Any way to change this?
Nasir Razzaq

Are you using the code project code I linked?
Cluskitt

ASKER
No, just a normal formview. I was trying to avoid having lots of code (especially because I'll have to document all code for others, and I hate documenting :P).

Is the code you linked the only way (or similar) to have this kind of Access-like behaviour?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Nasir Razzaq

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Cluskitt

ASKER
Those solutions work. Thanks a lot. :)
Nasir Razzaq

Glad to help :-)