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

Discussion in 'ASP .Net' started by Keithb, Oct 26, 2006.

  1. Keithb

    Keithb Guest

    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
     
    Keithb, Oct 26, 2006
    #1
    1. Advertising

  2. Keithb

    LosManos Guest

    hejdig.

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

    HTH

    /OF

    ----------

    > 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?
     
    LosManos, Oct 26, 2006
    #2
    1. Advertising

  3. Keithb

    kzmm Guest

    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

    Keithb wrote:
    > 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
     
    kzmm, Oct 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,474
    Brian Hoops
    Oct 28, 2004
  2. Replies:
    0
    Views:
    1,217
  3. Earl Teigrob
    Replies:
    1
    Views:
    423
    Shravan
    Mar 1, 2004
  4. Jurjen de Groot
    Replies:
    0
    Views:
    319
    Jurjen de Groot
    May 19, 2008
  5. SpamProof
    Replies:
    4
    Views:
    284
    SpamProof
    Jan 17, 2004
Loading...

Share This Page