Re: How to hide datagrid column based on user role

Discussion in 'ASP .Net' started by Raterus, Feb 19, 2004.

  1. Raterus

    Raterus Guest

    I've always just set the column I want(with an id set so you can access it)
    "visible" to "false"

    <asp:boundcolumn id="myBoundCol2Hide" runat="server">
    ...
    myBoundCol2Hide.visible = false

    this doesn't stop any binding to the column though, it just doesn't display
    it when it is rendered.

    "Reza Nabi" <> wrote in message
    news:...
    > I have a datagrid control. Based on the user role, i need to hide one of

    the column (the first column with a magnifying glass icon).
    > Lets say, if urser's roleID is 1, they can have have the link button to

    edit the clientele number.
    > What is the best way to accomplish this?
    > Any help/pointer would be grealy appreciated.
    > Thanks,
    >
    > Reza Nabi
    >
    > ---begin datagrid ----
    >
    >
    > &lt;asp:datagrid runat="server" id="gridCurrentErrors"

    autogeneratecolumns="false" &gt;
    > &lt;headerstyle backcolor="#797979" font-bold="true" forecolor="white"

    horizontalalign="center" /&gt;
    > &lt;alternatingitemstyle backcolor="#eeeeee" /&gt;
    > &lt;pagerstyle backcolor="#797979" font-bold="true" forecolor="white"

    /&gt;
    > &lt;Columns&gt;
    > &lt;asp:buttoncolumn runat="server" headertext=""
    > buttontype="linkbutton" commandname="EditClieteleCall"
    > Text="&lt;img title='Edit Clientele call...' border='no'

    src='images/mg.gif' /&gt;" &gt;
    > &lt;/asp:buttoncolumn&gt;
    > &lt;asp:boundcolumn runat="server" datafield="clientele_call"

    headertext="Call Number" /&gt;
    > &lt;asp:boundcolumn runat="server" datafield="starttime"

    headertext="Start" /&gt;
    > &lt;asp:boundcolumn runat="server" datafield="region_name"

    headertext="Region" /&gt;
    > &lt;asp:boundcolumn runat="server" datafield="site_name" headertext="Site"

    /&gt;
    >
    > &lt;/Columns&gt;
    > &lt;/asp:DataGrid&gt;
    >
    > ---end datagrid ----
    >
    > ---begin code behind to bind the datagrid---
    > // get the role_id who currently loged on
    > int roleID = Convert.ToInt32(RmsLiteSecurity.GetRoleID());
    > int userID = Convert.ToInt32(RmsLiteSecurity.GetUserID());
    > CurrentError ce = new CurrentError();
    > DataSet ds = ce.GetCurrentErrors(userID);
    > gridCurrentErrors.DataSource = ds.Tables[0].DefaultView;
    > gridCurrentErrors.DataBind();
    >
    >
    > ---end code behind to bind the datagrid ----
     
    Raterus, Feb 19, 2004
    #1
    1. Advertising

  2. Hello Raterus
    Thanks so much for your prompt help. As per Suresh, following code did the trick
    if (roleID == 1
    gridCurrentErrors.Columns[0].Visible = true
    els
    gridCurrentErrors.Columns[0].Visible = false

    Out of curiousity, i was trying your solutions as well. But when i was adding 'ID' attribute to BoundColumn i got the following error from visual studio.NET 2003
    ERROR: Could not find any attribute 'ID' of element 'BoundColumn

    Do i need to upgrade my visual studio
    Thanks

    Rez
     
    =?Utf-8?B?UmV6YSBOYWJp?=, Feb 20, 2004
    #2
    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. Jesper Stocholm
    Replies:
    2
    Views:
    8,174
    John Saunders
    Aug 23, 2003
  2. Liet Kynes
    Replies:
    0
    Views:
    517
    Liet Kynes
    Nov 26, 2003
  3. =?Utf-8?B?U3VyZXNo?=

    RE: How to hide datagrid column based on user role

    =?Utf-8?B?U3VyZXNo?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    438
    =?Utf-8?B?UmV6YSBOYWJp?=
    Feb 20, 2004
  4. vishnu
    Replies:
    1
    Views:
    1,232
    Patrick.O.Ige
    Mar 25, 2006
  5. Kursat
    Replies:
    1
    Views:
    331
    Dominick Baier
    May 7, 2007
Loading...

Share This Page