melli111
asked on
ASP.NET gridview based on permissions?
I have asn ASP.NET Gridview that displays a Delete button and a DetailsView that displays an Edit button. I would like to make these two buttons ONLY display if a user has access to perform Edit or Delete operations, with the information of who has access being contained in a database table. How would I go about doing this?
ASKER
Thank you, my next question is, I would like for the Delete button on the GridView to be in the very last column to the right. After the statement "GridView1.AutoGenerateDel eteButton = true;", is there a way to specify which row to place the Delete button in? It defaults to the very first row and I do not want it there.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This worked great, thank you. The very last thing I need, is that I want the Edit button on the DetailsView to be aligned on the right side. Is there any way to do that?
Yes! this easy way ;)
<asp:DetailsView ID="DetailsView1" runat="server" OnModeChanging="DetailsView1_ModeChanging">
<CommandRowStyle HorizontalAlign="Right" />
</asp:DetailsView>
I don't want to steal any of yv989c's credit here, as he's answered so well, but I just wanted to point out, in case you're using Visual Studio, that you can order the columns and set the alignment etc in the Edit Columns gui.
The styles can also be controlled using CSS files, examples below
The styles can also be controlled using CSS files, examples below
.mGrid {
background-color: #fff;
margin: 5px 0 10px 0;
border: solid 1px #525252;
border-collapse:collapse;
vertical-align:top;
}
.mGrid td {
padding: 2px;
border: solid 1px #c1c1c1;
color: #717171;
vertical-align:top;
}
.mGrid th {
color: Black;
background: #424242 ;
font-size: 0.9em;
text-align:center;
}
.mGrid .alt { background: #fcfcfc; }
Open in new window
You can download the aspx file here:GridViewPermissions.aspx
The best way to check permissions is to use a role provider or implement your own authentication method to be able to use the Page.User.IsInRole("") method, but I did this example to give you a start.
I hope this help.