473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

User Roles

58 New Member
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.
Sep 19 '07 #1
14 1222
aliasruel
73 New Member
Hi,
you can use panel object control dragged in you web page.

regards,
Ruel




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.
Sep 19 '07 #2
kewldudehere
58 New Member
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?
Sep 19 '07 #3
Frinavale
9,735 Recognized Expert Moderator Expert
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
Sep 19 '07 #4
kewldudehere
58 New Member
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.
Sep 19 '07 #5
Frinavale
9,735 Recognized Expert Moderator Expert
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):
Expand|Select|Wrap|Line Numbers
  1. If the User isInRole("aquatics") Then
  2.     myGridView.DataSource = CreateAquaticsDataSource()
  3. If the User isInRole("dogs") Then
  4.     myGridView.DataSource = CreateDogsDataSource()
  5. End Ifs
  6.  
  7. myGridView.DataBind
  8.  
Where you'd have a function CreateAquaticsDataSource that returns a DataView or some such thing that contains a table with all the different types of aquatics stuff....and a function called CreateDogsDataSource 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
Expand|Select|Wrap|Line Numbers
  1. Private Function CreateAquaticsDataSource As DataView
  2.   Dim dr As Data.DataRow
  3.   Dim dt As Dat.DataTable
  4.  
  5.    dt.Columns.Add(New Data.DataColumn("Fish Variety", GetType(String))
  6.    dt.Columns.Add(New Data.DataColumn("Price", GetType(String))
  7.  
  8.    dr = dt.NewRow
  9.    dr("Fish Variety") = "Gold Fish"
  10.    dr("Price") = "$12.95"
  11.  
  12.    dt.Rows.Add(dr)
  13.  
  14.    dr = dt.NewRow
  15.    dr("Fish Variety") = "Beta Fish"
  16.    dr("Price") = "$10.95"
  17.  
  18.    dt.Rows.Add(dr)
  19.  
  20. 'this will return a DataView with 2 columns named "Fish Variety" and "Price"
  21. 'it has 2 rows of data in it.
  22.  
  23.    Return New Data.DataView(dt)
  24.  
  25. End Function
  26.  
  27.  
  28. Private Function CreateDogsDataSource As DataView
  29.   Dim dr As Data.DataRow
  30.   Dim dt As Dat.DataTable
  31.  
  32.    dt.Columns.Add(New Data.DataColumn("Dog Toy", GetType(String))
  33.    dt.Columns.Add(New Data.DataColumn("Colour", GetType(String))
  34.    dt.Columns.Add(New Data.DataColumn("Price", GetType(String))
  35.  
  36.    dr = dt.NewRow
  37.    dr("Dog Toy") = "Squeaky Toy"
  38.    dr("Colour") = "Blue"
  39.    dr("Price") = "$15.00"
  40.  
  41.    dt.Rows.Add(dr)
  42.  
  43.    dr = dt.NewRow
  44.    dr("Dog Toy") = "Tug-of-War Toy"
  45.    dr("Colour") = "White and Red"
  46.    dr("Price") = "$23.99"
  47.  
  48.    dt.Rows.Add(dr)
  49.  
  50. 'this DataView has 3 columns: Dog Toy, Colour, and Price.
  51. 'it has 2 rows of data in it.
  52.    Return New Data.DataView(dt)
  53.  
  54. End Function
  55.  
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
Sep 19 '07 #6
nmsreddi
366 Contributor
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
Sep 20 '07 #7
Frinavale
9,735 Recognized Expert Moderator Expert
...
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
Sep 20 '07 #8
kewldudehere
58 New Member
Thanks guys for all ur replies..i will try the same way and let u know if i am stuck..Thanks
Sep 20 '07 #9
kewldudehere
58 New Member
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
Sep 20 '07 #10
Frinavale
9,735 Recognized Expert Moderator Expert
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.

:)
Sep 20 '07 #11
kewldudehere
58 New Member
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:hyperlinkfield too...but no good...So what is the appropriate column should i use from the given columsn of gridview.
Sep 20 '07 #12
Frinavale
9,735 Recognized Expert Moderator Expert
I tried to use asp:hyperlinkfield 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?
Sep 20 '07 #13
kewldudehere
58 New Member
HI.. these are the columns for first query for a particular role.
Expand|Select|Wrap|Line Numbers
  1.   <asp:HyperLinkField DataTextField="WeekBeginningDate" 
  2.                                     DataNavigateUrlFields="TimeCardID" 
  3.                                     DataNavigateUrlFormatString="ActivityEntry.aspx?id={0}" 
  4.                                     HeaderText="WeekBeginningDate" 
  5.                                     SortExpression="WeekBeginningDate"/>
  6.  
  7.  
  8.                <asp:BoundField DataField="TC_STATUS" HeaderText="Timecard Status" SortExpression="TC_STATUS" HtmlEncode="false" HeaderStyle-Wrap="false" />
These are next set of cols in same page for second query and second role
Expand|Select|Wrap|Line Numbers
  1. <asp:HyperLinkField DataTextField="TotalCountofTimeCards" DataNavigateUrlFields="TimeCardID" DataNavigateUrlFormatString="ActivityEntry.aspx?id={0}" HeaderText="Total Count of TimeCards"  />
  2.                <asp:HyperLinkField DataTextField="TotalApproved" DataNavigateUrlFields="TimeCardID" DataNavigateUrlFormatString="ActivityEntry.aspx?id={0}" HeaderText="Total Approved"  />
  3.  

In the code behind of page load event i have,,.,
Expand|Select|Wrap|Line Numbers
  1.  If role = "Team Manager" Then
  2.             query = "select TimeCardID,WeekBeginningDate,TC_Status from timecards "
  3.             FillGrid(grdTimeCardStatus, query)
  4.  
  5.         End If
  6.         If role = "Line Item Approver" Then
  7.             query = "select TimeCardID,TotalCountofTimeCards,TotalApproved from timecards"
  8.             FillGrid(grdTimeCardStatus, query)
  9.  
  10.         End If
Sep 21 '07 #14
Frinavale
9,735 Recognized Expert Moderator Expert
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:
Expand|Select|Wrap|Line Numbers
  1.  Protected Sub MyGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV_SearchResults.RowDataBound
  2.  
  3.         'setting the Last column to be invisible
  4.         e.Row.Cells(e.Row.Cells.Count - 1).Visible = False
  5.         'setting the Second Last column to be invisible
  6.         e.Row.Cells(e.Row.Cells.Count-2).Visible = False
  7.     End Sub
  8.  

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
Expand|Select|Wrap|Line Numbers
  1. 'My VB.NET code
  2.  
Or if I wanted to post my ASP code I would type
Expand|Select|Wrap|Line Numbers
  1. 'My Asp Code
  2.  
This just makes things easier to read and follow.

Thanks!

-Frinny
Sep 21 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3593
by: Mad Scientist Jr | last post by:
I would like to write a vb.asp.net function Private Function fn_sGetRoles(byval sDelimiter as string) As String that simply returns a delimited list of all the roles a user belongs to. I...
1
1180
by: Charles | last post by:
Hello, I tried posting this yesterday, and I have not seen it yet this morning. Thinking that something went wrong getting this question posted I am posting it again. Sorry if this does end up...
8
4876
by: Mark White | last post by:
Hey everyone I'm having a great deal of problems finding this information through google and yahoo, so I turn to you on this. I have a Windows app running on XP. I am able to caputre the...
3
2015
by: tshad | last post by:
I am playing with GenericPrincipal classes and am using a sample program to test it. The problem is that even though I set the roles (which shows the roles in the Context.User as being there),...
1
3615
by: ^MisterJingo^ | last post by:
Hi all, I've been searching the net for a way to programatically add a user to a role on successful registration. Not finding anything useful I decided to experiment and came up with the...
3
8934
by: =?Utf-8?B?Q2hhcmxlc0E=?= | last post by:
hi folks, I've got XP pro service pack 2 VS 2005 TSE with ASP.net 2.0 and C# I'm doing an example from Stephen Walther's so far excellent book and he has a whole load of stuff to add the...
4
8207
by: alexandis | last post by:
There are tons of articles about custom role and provider membership, but they just tear me apart and confuse :( The situation is following: I use DB2, so I wrote custom role + membership...
14
3244
by: chromis | last post by:
Hi, I've been trying to implement a more OOP oriented approach to dealing with user security on one of my websites, and I am trying to validate the user against an array of roles, however I am...
4
1387
by: John Devlon | last post by:
Hi, I've created a small application with some user-authentication and roles. I would like to show/hide some navigation parts based on the users role. Could someone please tell me what the...
2
1867
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.