Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to programmatically set datagrid column readonly

Status
Not open for further replies.

BillKuhn

Programmer
Jun 1, 2007
21
US
I've inherited a website that we are trying to build some security into w/o major rewrite.

This is in ASP 2.0 with VB codebehind. We are using ASP.net forms based security and that is working well.

We now need to add a user role that will have READONLY access to a bunch of the existing forms. These forms have most any server side controls on them.

I want to cycle through the existing controls on a page (and recursively drill into containers like gridviews and datagrids) to set controls readonly based on the current user's role membership.

This is pretty straightforward for textboxes and such, but for grids I am lost.

I'm used to VFP where this would be trivial. It looks like it is trivial in Winforms too.

How can this be done in ASP.NET 2.0???

Help?

Bill Kuhn - MCSE
bkuhn@kuhngroup.com
The Kuhn Group, Inc.
 
>> but for grids I am lost.

why? it is the same approach as other controls!

another way to do this is to add your code to the ItemDataBound of the grid...

Known is handfull, Unknown is worldfull
 
?? I do not see a ReadOnly property for DataGrid or GridView controls. Am I missing something obvious (it would not be the first time)??

Bill Kuhn - MCSE
bkuhn@kuhngroup.com
The Kuhn Group, Inc.
 
you dont have that property for the entire column of the grid. however you can make disable control in the grid using this event...

Known is handfull, Unknown is worldfull
 
OK. Disabling the controls seems to work OK, although on grids that have paging won't that disable the paging functionality too?

Bill Kuhn - MCSE
bkuhn@kuhngroup.com
The Kuhn Group, Inc.
 
>>OK. Disabling the controls seems to work OK, although on grids that have paging won't that disable the paging functionality too?


not at all. you can decide based on the ItemType at run time...

Known is handfull, Unknown is worldfull
 
OK - I think I'm set.

I cycle through all Controls in the page Controls collection (and recursively through any controls' controls collections) looking for specific webcontrol types. Based on the webcontrol type, I set readonly or enabled. It seems to work fine!

Thanks for your help!

Bill Kuhn - MCSE
bkuhn@kuhngroup.com
The Kuhn Group, Inc.
 
your welcome :)...

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top