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

  • Home
  • SEARCH
  • 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 7550227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:09:32+00:00 2026-05-30T10:09:32+00:00

I need a count for the GetUsers but I have 3 different calculations either

  • 0

I need a count for the GetUsers but I have 3 different calculations either by alpha, search and byEmail parameters what can I do in this situation for my ObjectDataSource SelectCount method

public class Users
{
    public IList<MembershipUser> GetUsers(string alpha, string search, bool byEmail, int startRowIndex, int maximumRows)
    {
        IList<MembershipUser> users = null;

        if (alpha != null && search == null)
        {
            users = Membership.GetAllUsers().Cast<MembershipUser>().Where(x => x.UserName.StartsWith(alpha) == true).ToList();
        }
        else if (search != null && !byEmail)
        {
            users = Membership.FindUsersByName(search).Cast<MembershipUser>().Skip(maximumRows * startRowIndex).Take(maximumRows).ToList();
        }
        else
        {
            users = Membership.FindUsersByEmail(search).Cast<MembershipUser>().Skip(maximumRows * startRowIndex).Take(maximumRows).ToList();
        }

        return users;

    }

    public int GetUserCount()
    {

    }

Updated C#:

    public IEnumerable<MembershipUser> GetUsers(string alpha, string searchBy, string searchText, int startRowIndex, int maximumRows)
    {
        var users = Membership.GetAllUsers().Cast<MembershipUser>();

        if (alpha != null && string.IsNullOrEmpty(searchBy))
        {
            users = users
                .Where(x => x.UserName.StartsWith(alpha, StringComparison.OrdinalIgnoreCase))
                .Skip(maximumRows * startRowIndex)
                .Take(maximumRows).ToList();
        }
        else if (searchBy == "User Name" && !string.IsNullOrEmpty(searchText))
        {
            users = users.Where(x => x.UserName == searchText)
                .Skip(maximumRows * startRowIndex)
                .Take(maximumRows).ToList();
        }
        else if (searchBy == "Email" && !string.IsNullOrEmpty(searchText))
        {
            users = users.Where(x => x.Email == searchText)
                .Skip(maximumRows * startRowIndex)
                .Take(maximumRows).ToList();
        }
        else
        {
            users = null;
        }

        return users;

    }
  • 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-30T10:09:33+00:00Added an answer on May 30, 2026 at 10:09 am

    Something like the following should work:

    public int GetUserCount(string alpha, string search, bool byEmail, int startRowIndex, int maximumRows)
    {
        var users = Membership.GetAllUsers().Cast<MembershipUser>();
    
        if (alpha != null && search == null)
        {
            users = users.Where(x => x.UserName.StartsWith(alpha) == true);
        }
        else if (search != null && !byEmail)
        {
            users = users.FindUsersByName(search).Cast<MembershipUser>();
        }
        else
        {
            users = users.FindUsersByEmail(search);
        }
    
        return users.Count();
    }
    

    I would be more comfortable with this approach if FindUsersByName and FindUsersByEmail returned objects related to IEnumerable<T> so you could depend on the lazy nature of LINQ, but in this case it doesn’t matter since you’re doing a count. I’d recommend some form of Select to limit the fields being queried over, but in your second two cases, they’ll pull all results anyway so it would be without benefit 2/3 possible situations. If you find that more often than not the query is done by UserName then it would probably be worth adding there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a a large text file (over 70mb) and need to count the
We need to read and count different types of messages/run some statistics on a
I have tracking table tbl_track with id, session_id, created_date fields I need count unique
I need to count repeated rows but only show them in results if at
I have a homepage need to count the usage frequency of Notepad or Calc
I have a table where i store all product orders. I need to count
I want to echo only the first 10 rows, but I need to count
I have a List<int> and need to count how many elements with (value <
I need to count number of sessions but it dose not work when I
I need to count SHA1 checksum of NSData object. How can I do it?

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.