I need ideas…
I have a classic scenario with a twist, containing the following tables: Users, Roles, UsersInRoles.
In my webpage I have some Comboboxes (i.e. DropDownList + TextBox), one for each Role which contain all the Users for that particular Role. What I would like each of them to contain instead is a full list of all users, but grouped and ordered like so…
- Users for only the given role (ordered by name) – My intention is to highlight these items.
- The rest of the users, with no repeats (ordered by name)
I have been playing around with some SQL and VB trying to work my way toward a solution, but it is not clear yet which is the best approach, nor how to fully implement the solution. I have only figured out small bits and pieces. Forgive me for refraining from posting any code for now. I hoping for some fresh ideas and a clever solution that won’t put a lot of demand on the server.
To help you with relevant suggestions here’s the structure of my tables:
Users (ID, Username, Name)
Roles (ID, Role)
UsersInRoles (ID, UserID, RoleID)
And the query I wrote to that gave me all the subgroups I need to get to where I want I think.
select u.ID, Name, RoleID from UsersInRoles
inner join Users u on UserID = u.ID --This is only to return a name rather than ID
order by ReviewerRoleID, Name
Using the recommendation by Tim, I may use some codebehind like this to bind to each respective drop down list. The one concern I have is that I’m performing a query for each Role which poses a potential burden on the server every time the page is accessed by a user.
Private Sub PopulateUserInRoleCombobox(ByVal key As Integer, ByVal ddl As DropDownList)
Try
Dim dt As New DataTable
Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("tcomConnectionString").ConnectionString)
Dim spSelect As New SqlCommand("spGetUserInRoleList", connection)
spSelect.CommandType = CommandType.StoredProcedure
Dim RoleID As New SqlParameter("@GivenRoleID", SqlDbType.Int)
RoleID.Value = key
spSelect.Parameters.Add(RoleID)
Dim da As New SqlDataAdapter(spSelect)
da.Fill(dt)
End Using
ddl.DataSource = dt
ddl.DataBind() 'Bind results to the DropDownList
Catch ex As Exception
'Error Message
End Try
End Sub
And the last step is to figure out how best to write the Javascript for styling each list item depending on if it’s a member of the given role or not. >.<
Thank you 🙂
I assume that this is T-SQL for you(if using SQL-Server)
This is one way to retrieve the data via ADO.NET: