Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7168037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:41:54+00:00 2026-05-28T14:41:54+00:00

I need ideas… I have a classic scenario with a twist, containing the following

  • 0

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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:41:55+00:00Added an answer on May 28, 2026 at 2:41 pm

    I assume that this is T-SQL for you(if using SQL-Server)

    ;WITH UserRoles AS(
        SELECT U.UserName
        ,R.RoleName
        ,Row_Number()Over(Order By CASE WHEN R.RoleID= @GivenRoleID THEN 0 ELSE 1 END,UserName)As SortOrder
        ,Row_Number()Over(Partition By UserName Order By CASE WHEN R.RoleID= @GivenRoleID THEN 0 ELSE 1 END,RoleName)As UserRoleNumber
        FROM  Users AS U INNER JOIN
        UsersInRoles ON U.UserId = UsersInRoles.UserId INNER JOIN
        Roles AS R ON UsersInRoles.RoleId = R.RoleId
    )
    SELECT UserName,RoleName
    FROM UserRoles
    WHERE UserRoleNumber=1
    ORDER By SortOrder
    
    • CASE (Transact-SQL)
    • ROW_NUMBER (Transact-SQL)
    • WITH common_table_expression (Transact-SQL)

    This is one way to retrieve the data via ADO.NET:

    Public Shared Function GetUsers(forRoleID As Guid) As DataTable
        Dim tblUser As New DataTable
        Using sqlCon As New SqlClient.SqlConnection(My.Settings.ConnectionString)
            Dim sqlCmd = New SqlClient.SqlCommand()
            sqlCmd.CommandType = CommandType.StoredProcedure
            sqlCmd.CommandText = "dbo.spGetUserInRoleList"
            sqlCmd.Connection = sqlCon
            sqlCmd.Parameters.AddWithValue("@GivenRoleID", forRoleID)
            Using objAdapter As New SqlClient.SqlDataAdapter(sqlCmd)
                Try
                    objAdapter.Fill(tblUser)
                Catch ex As Exception
                    ' log exception etc. '
                End Try
            End Using
        End Using
    
        Return tblUser
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some ideas for a homework assignment that I have. Consider the following
I have a problem and i need some ideas to solve it: I have
I need some ideas for a design problem, i have the need for a
I need some ideas how to create a activation algorithm. For example i have
I need some ideas on how I can best solve this problem. I have
today i have direct a problem :P i just need some ideas... how do
I just need some ideas for an approach to sorting results. Here's the scenario:
I need ideas for structuring and processing data with revisions. For example, I have
I have no ideas how to do this, so I need your advice. I
I have repaired .net 4.0 but (still) cannot find: Ilasm.exe Any ideas? I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.