Page view counter

gridview security

Last post 03-05-2007 6:42 AM by mlawton40. 8 replies.

Sort Posts:

  • gridview security

    11-27-2006, 4:34 PM
    • Loading...
    • mso789
    • Joined on 11-27-2006, 9:19 PM
    • Posts 10
    • Points 21

    I am building an application that need to be flexible enough to hide certain pieces of information withing a page based on who the user is.  

     

    More specifically, I have a gridview/formview which needs to allow certain users to edit/insert/delete information while at the same time would limit other users to view information.

    Is this possible and how will I go about doing this ?

    Thanks in advance.

  • Re: gridview security

    11-27-2006, 8:37 PM
    Answer
    • Loading...
    • ulysses098
    • Joined on 08-15-2006, 4:38 AM
    • Posts 18
    • Points 62
    yes. you can access the controls inside a gridview and formview, then their are events in the gridview called rowdatabound which you can use to show or hide certain controls inside that row.
  • Re: gridview security

    12-05-2006, 5:03 PM
    • Loading...
    • mso789
    • Joined on 11-27-2006, 9:19 PM
    • Posts 10
    • Points 21

    What about the FormView controls.   How do I allow administrators to see the edit/insert/delete functions and hide those controls from any other user ?

    Also, going back to your response, what exactly am I to type under the rowdatabound gridView control ?  Can you provide me with a sample ?

    Thanks.
     

  • Re: gridview security

    12-07-2006, 9:22 PM
    • Loading...
    • benvan
    • Joined on 10-28-2006, 12:08 AM
    • Posts 8
    • Points 25

    This is a very good example of how NOT to ask a question.

     

    Do you have any knowledge of C# or VB?

     on rowcreated, Use e.Row.Cells( index of required cell, in this case probably 0 ).Visible = False

     

    likewise, change the index for any other columns which you want to hide. I would suggest writing a hidecolumns function.

  • Re: gridview security

    01-04-2007, 10:45 PM
    • Loading...
    • ulysses098
    • Joined on 08-15-2006, 4:38 AM
    • Posts 18
    • Points 62

    well let us assume you have a usertype session that will determine if we will view the edit/insert/delete button.

        protected void example_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                if(Session["usertype"] == "admin"){
                        Button btnsample= (Button)e.Row.FindControl("insertbutton");

                         btnsample.visible = true;
                 }

                else

                {

                        Button btnsample= (Button)e.Row.FindControl("insertbutton");                    

                        btnsample.visible = false;

                }
            }
        }

  • Re: gridview security

    01-04-2007, 10:51 PM
    • Loading...
    • ulysses098
    • Joined on 08-15-2006, 4:38 AM
    • Posts 18
    • Points 62
    you can also use the load event of a formview, and put the condition of hiding and showing the edit/insert/delete button.
  • Re: gridview security

    03-05-2007, 6:06 AM
    • Loading...
    • mlawton40
    • Joined on 01-11-2007, 10:47 AM
    • Posts 76
    • Points 8

    Hi, Im just trying this and have the following code, which I have used from the  

    protected void Delete_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (Roles.IsUserInRole(User.Identity.Name, "Administrator"))
                {
                    ImageButton btnDel = e.Row.Cells[6].Controls[0] as ImageButton;
                    btnDel.visible = true;
                }
                else
                {
                    ImageButton btnDel = e.Row.Cells[6].Controls[0] as ImageButton;
                    btnDel.Visible = false;
                }
            }
        } 
     above example.

     

    The problem is the following message appears:

    'System.Web.UI.WebControls.ImageButton' does not contain a definition for 'visible'

    Any idea? Cheers, Mark

  • Re: gridview security

    03-05-2007, 6:36 AM
    • Loading...
    • macal_vm
    • Joined on 12-08-2006, 1:37 PM
    • Posts 153
    • Points 156

    also, u can aways create a admin.aspx page and set the view to insert/edit or whatever u want. the same way, u can set the view for normal users to read only.

    this way u need only to protect the page.

  • Re: gridview security

    03-05-2007, 6:42 AM
    • Loading...
    • mlawton40
    • Joined on 01-11-2007, 10:47 AM
    • Posts 76
    • Points 8

    but any ideas about the above problem?

     Cheers, Mark

Page 1 of 1 (9 items)