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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Question

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
US
I have a datagrid on a page where I have enabled an edit and delete buttons. If the user is NOT an manager, he/she will not be able to edit the grid. Where is the best place (sub) to turn this column off. where I bind it maybe?

I posted this by mistake in the SQL forum. What a fool am I....
 
If you just need to show/hide those columns, based on user's role, then you can do it after you bound the grid, i.e.:

//assume that your edit/delete columns are first & second in the grid
int editColumnIndex = 0;
int deleteColumnIndex = 1;

if(// logic for detecting user role here - not admin)
{
mygrid.Columns[0].Visible = false;
mygrid.Columns[1].Visible = false;
}



 
Very cool. I was looking to name them so I could change the order later. You know the user's will want to add columns, and there go's the col numbers. :-(
 
How about this then:

foreach(DataGridColumn dc in this.myGrid.Columns)
{
if(//user is not admin)
{
if(dc.GetType().Name == "EditCommandColumn")
{
dc.Visible = false;
break;
}
}
}
 
You can iterate through the controls collection of cells I believe, (not on my development PC I'm afraid, so no .Net), so you check the controls collection of each of the cells for each column on the the first Item, looking for a Button control. When you find it, get the Column index that has this control in and set the visible property of the column to false if the Role is not Manager...

Would something like that work?

Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top