How to hide a GridView column when the column's Visible property does not support databinding?

K

Keithb

I need to hide a GridView's "edit" column if the user's role does not
support editing. However, the column's Visible property does not support
databinding. Is there a workaround?

Thanks,

Keith
 
L

LosManos

hejdig.

myGrid.Columns[ x ].Visible = ( NotSupportEditing == myUser.Role );

HTH

/OF
 
K

kzmm

Hi

if u set the visiblity of a column false then it cant be bind. The
solution to this problem is

i hope u dont mind the code is in vb.net if u ve any problem. then ask
me i will help u in converting this code to c# .
1. create a RowCreated event handler for that datagrid or gridview and
then pass the no of that column you want to hide. and if hide.

what happening here is: if u set the visiblity to false b4 data binding
then cloumn will not be created. and rowcreated event fired after
RowDataBound event fired. so here u r fee to hide that column.



Protected Sub grdMaster_RowCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
grdMaster.RowCreated

e.Row.Cells(0).Visible = False
e.Row.Cells(1).Visible = False



End Sub

i hope it will be helpful for u
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top