User Roles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kewldudehere
    New Member
    • Jan 2007
    • 58

    User Roles

    Hi,

    I want to display different type of grid with different cols in a same page based upon the role of user logged in .
    Can anybody give me a hint how to approach to the solution.

    Bye.
  • aliasruel
    New Member
    • Sep 2007
    • 73

    #2
    Hi,
    you can use panel object control dragged in you web page.

    regards,
    Ruel




    Originally posted by kewldudehere
    Hi,

    I want to display different type of grid with different cols in a same page based upon the role of user logged in .
    Can anybody give me a hint how to approach to the solution.

    Bye.

    Comment

    • kewldudehere
      New Member
      • Jan 2007
      • 58

      #3
      Will Panel Cotrol achieve this functionality.? I am just wondering, if i place 3 gridview controls in one panel but only 1 will be displayed at a time based upon the role of user logged in. Will the other 2 appear as blank or will they be hidden and appear as if only 1 control exist on that page.?

      Like if i place one type of gridview for basic user first in a panel and place second gridview control for manager next in a same panel and if manager logs in will he see the first gridview control as blank in the panel.?

      I am new to panel control. Can u guide me in this?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by kewldudehere
        Will Panel Cotrol achieve this functionality.? I am just wondering, if i place 3 gridview controls in one panel but only 1 will be displayed at a time based upon the role of user logged in. Will the other 2 appear as blank or will they be hidden and appear as if only 1 control exist on that page.?

        Like if i place one type of gridview for basic user first in a panel and place second gridview control for manager next in a same panel and if manager logs in will he see the first gridview control as blank in the panel.?

        I am new to panel control. Can u guide me in this?
        I don't think you need to use the Panel Control to do this.


        How are you defining the Role's of your user?
        Are you using Membership to do this?

        What you need to do is create a custom data source for your grid view based on the user's role...

        So, when you are generating the data source for the GridView, check the user's role first and generate the data source accordingly.

        Does this make sense?

        -Frinny

        Comment

        • kewldudehere
          New Member
          • Jan 2007
          • 58

          #5
          HI Frinny,

          I have Roles defined in Roles table. Each role will have different view of the gridview with different cols.

          So do i need to write 3 seperate Queries for 3 roles and bind the Query to gridview. If this is the case, how to define gridview in aspx page. Do i need to mention all column names that can appear in the grid and bind those cols for appropriate col in database.? If i do like this, the cols that are not being displayed for particulat role will be displayed as blank? I have never worked in this scenario before.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by kewldudehere
            HI Frinny,

            I have Roles defined in Roles table. Each role will have different view of the gridview with different cols.

            So do i need to write 3 seperate Queries for 3 roles and bind the Query to gridview. If this is the case, how to define gridview in aspx page. Do i need to mention all column names that can appear in the grid and bind those cols for appropriate col in database.? If i do like this, the cols that are not being displayed for particulat role will be displayed as blank? I have never worked in this scenario before.
            Yup you're getting it.

            For example:
            So say you have employees that work in 2 different departments. Some employees will be in the role that lets them see Aquatics products and some employees will be in the role that lets them see Dog products.....
            So, basically you want to do something like this (please note this is pseudo code):
            Code:
            If the User isInRole("aquatics") Then
                myGridView.DataSource = CreateAquaticsDataSource()
            If the User isInRole("dogs") Then
                myGridView.DataSource = CreateDogsDataSource()
            End Ifs
            
            myGridView.DataBind
            Where you'd have a function CreateAquaticsD ataSource that returns a DataView or some such thing that contains a table with all the different types of aquatics stuff....and a function called CreateDogsDataS ource that returns a DataView or some such thing that contains a table with all the different types of dogs stuff...

            These DataViews will set the GridView's column titles and fill the GridView with information...

            eg
            [code=vbnet]
            Private Function CreateAquaticsD ataSource As DataView
            Dim dr As Data.DataRow
            Dim dt As Dat.DataTable

            dt.Columns.Add( New Data.DataColumn ("Fish Variety", GetType(String) )
            dt.Columns.Add( New Data.DataColumn ("Price", GetType(String) )

            dr = dt.NewRow
            dr("Fish Variety") = "Gold Fish"
            dr("Price") = "$12.95"

            dt.Rows.Add(dr)

            dr = dt.NewRow
            dr("Fish Variety") = "Beta Fish"
            dr("Price") = "$10.95"

            dt.Rows.Add(dr)

            'this will return a DataView with 2 columns named "Fish Variety" and "Price"
            'it has 2 rows of data in it.

            Return New Data.DataView(d t)

            End Function


            Private Function CreateDogsDataS ource As DataView
            Dim dr As Data.DataRow
            Dim dt As Dat.DataTable

            dt.Columns.Add( New Data.DataColumn ("Dog Toy", GetType(String) )
            dt.Columns.Add( New Data.DataColumn ("Colour", GetType(String) )
            dt.Columns.Add( New Data.DataColumn ("Price", GetType(String) )

            dr = dt.NewRow
            dr("Dog Toy") = "Squeaky Toy"
            dr("Colour") = "Blue"
            dr("Price") = "$15.00"

            dt.Rows.Add(dr)

            dr = dt.NewRow
            dr("Dog Toy") = "Tug-of-War Toy"
            dr("Colour") = "White and Red"
            dr("Price") = "$23.99"

            dt.Rows.Add(dr)

            'this DataView has 3 columns: Dog Toy, Colour, and Price.
            'it has 2 rows of data in it.
            Return New Data.DataView(d t)

            End Function
            [/code]

            So what you need to do is somehow check what role your user is in and create a DataSource for your grid view based on the role that the user is in.

            Cheers!

            -Frinny

            Comment

            • nmsreddi
              Contributor
              • Jul 2006
              • 366

              #7
              Hello

              when you are using three different queries for different users ,its not a problem to show different data for different users just bind the grid in page load depending on the userid who so ever login ,

              but remember you cannot use template colmns in this case .make autogenerate columns as true and your queries should select only the required columns for a particular users

              Regards
              Last edited by Frinavale; Sep 20 '07, 01:09 PM. Reason: Fixed [code] tags so that post is viewable

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #8
                Originally posted by nmsreddi
                ...
                but remember you cannot use template colmns in this case .make autogenerate columns as true and your queries should select only the required columns for a particular users
                Thanks Nmsreddi!

                I forgot to mention that :)

                -Frinny

                Comment

                • kewldudehere
                  New Member
                  • Jan 2007
                  • 58

                  #9
                  Thanks guys for all ur replies..i will try the same way and let u know if i am stuck..Thanks

                  Comment

                  • kewldudehere
                    New Member
                    • Jan 2007
                    • 58

                    #10
                    Hi, its not working. Its throwing me a runtime error as column not bound.
                    The column name that does'nt appear for particular role , is not getting bound by datasource which is obvious and throwing a runtime error.

                    I have used asp:bound field for this column.

                    Any suggetsions

                    Comment

                    • Frinavale
                      Recognized Expert Expert
                      • Oct 2006
                      • 9749

                      #11
                      Originally posted by kewldudehere
                      Hi, its not working. Its throwing me a runtime error as column not bound.
                      The column name that does'nt appear for particular role , is not getting bound by datasource which is obvious and throwing a runtime error.

                      I have used asp:bound field for this column.

                      Any suggetsions
                      As mentioned before, you cannot have your columns bound using this method.
                      Try removing your bound column and try again.

                      :)

                      Comment

                      • kewldudehere
                        New Member
                        • Jan 2007
                        • 58

                        #12
                        Originally posted by Frinavale
                        As mentioned before, you cannot have your columns bound using this method.
                        Try removing your bound column and try again.

                        :)
                        I tried to use asp:hyperlinkfi eld too...but no good...So what is the appropriate column should i use from the given columsn of gridview.

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Originally posted by kewldudehere
                          I tried to use asp:hyperlinkfi eld too...but no good...So what is the appropriate column should i use from the given columsn of gridview.
                          You cannot set the columns of the grid like that.

                          Could you please post snippets of your code so that we can help you better?

                          Comment

                          • kewldudehere
                            New Member
                            • Jan 2007
                            • 58

                            #14
                            HI.. these are the columns for first query for a particular role.
                            [code=asp]
                            <asp:HyperLinkF ield DataTextField=" WeekBeginningDa te"
                            DataNavigateUrl Fields="TimeCar dID"
                            DataNavigateUrl FormatString="A ctivityEntry.as px?id={0}"
                            HeaderText="Wee kBeginningDate"
                            SortExpression= "WeekBeginningD ate"/>


                            <asp:BoundFie ld DataField="TC_S TATUS" HeaderText="Tim ecard Status" SortExpression= "TC_STATUS" HtmlEncode="fal se" HeaderStyle-Wrap="false" />[/code]

                            These are next set of cols in same page for second query and second role
                            [code=asp]
                            <asp:HyperLinkF ield DataTextField=" TotalCountofTim eCards" DataNavigateUrl Fields="TimeCar dID" DataNavigateUrl FormatString="A ctivityEntry.as px?id={0}" HeaderText="Tot al Count of TimeCards" />
                            <asp:HyperLinkF ield DataTextField=" TotalApproved" DataNavigateUrl Fields="TimeCar dID" DataNavigateUrl FormatString="A ctivityEntry.as px?id={0}" HeaderText="Tot al Approved" />
                            [/code]


                            In the code behind of page load event i have,,.,
                            [code=vbnet]
                            If role = "Team Manager" Then
                            query = "select TimeCardID,Week BeginningDate,T C_Status from timecards "
                            FillGrid(grdTim eCardStatus, query)

                            End If
                            If role = "Line Item Approver" Then
                            query = "select TimeCardID,Tota lCountofTimeCar ds,TotalApprove d from timecards"
                            FillGrid(grdTim eCardStatus, query)

                            End If[/code]
                            Last edited by Frinavale; Sep 21 '07, 01:08 PM. Reason: Added [code] tags to make more legible

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              From what I understand, you are actually filling the GridView with the same data for each role Except for one you want to show 2 extra columns.

                              In this case I would recommend filling the GridView with the same amount of columns. Then in the method that handles the RowDataBound event, make those 2 extra rows invisible for the group that's not supposed to see this data.

                              Eg:
                              Code:
                               Protected Sub MyGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_SearchResults.RowDataBound
                                    
                                      'setting the Last column to be invisible
                                      e.Row.Cells(e.Row.Cells.Count - 1).Visible = False
                                      'setting the Second Last column to be invisible
                                      e.Row.Cells(e.Row.Cells.Count-2).Visible = False
                                  End Sub

                              If this doesn't help you let me know and we'll try something else.

                              Oh, and in the future please put code within [code] tags.
                              For instance if I wanted to post my VB.NET code I would type
                              Code:
                              'My VB.NET code
                              Or if I wanted to post my ASP code I would type
                              Code:
                              'My Asp Code
                              This just makes things easier to read and follow.

                              Thanks!

                              -Frinny
                              Last edited by Frinavale; May 28 '13, 04:56 PM. Reason: Fixed code tags

                              Comment

                              Working...