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 8869043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:23:30+00:00 2026-06-14T17:23:30+00:00

I’ve turned on paging on my gridview but when I try to change the

  • 0

I’ve turned on paging on my gridview but when I try to change the page, the postback data come back empty.

When the page loads for the first time, the data is there.

This is the first time i’ve done this so i’m probably doing something wrong.

The datasource is a membershipusercollection list.

Here’s my code…

protected void Page_Load(object sender, EventArgs e)
{
    count = 0;             

    switch (Request.QueryString["status"])
    {
        case "active":
            lblUserListTitle.Text = "Activated user accounts";
            break;
        case "inactive":
            lblUserListTitle.Text = "Inactive user accounts";
            break;
        case "locked":
            lblUserListTitle.Text = "Locked user accounts";
            break;
        case "online":
            lblUserListTitle.Text = "Users online";
            break;
        case "notverified":
            lblUserListTitle.Text = "Users accounts not yet verified";
            break;
        default:
            lblUserListTitle.Text = "All user accounts";
            break;
    }
    if (!IsPostBack)
        BindGrid();    

    lblSearchResult.Text = "There are " + count.ToString() + " registered users found.";
}
protected void BindGrid()
{
    MembershipUserCollection usersList = Membership.GetAllUsers();
    MembershipUserCollection filteredUsers = new MembershipUserCollection();

    foreach (MembershipUser user in usersList)
    {
        if (!Roles.IsUserInRole(user.UserName, "Admin") && !Roles.IsUserInRole(user.UserName, "Engineering"))
        {
            userProfile = Profile.GetProfile(user.UserName);

            if (txtFilterCustomerNo.Text.Length > 0)
            {
                ProfileCommon PC = Profile.GetProfile(user.UserName);
                if (PC.RaymarineAccountNo == txtFilterCustomerNo.Text.ToUpper())
                {
                    filteredUsers.Add(user);
                    count++;
                }
            }
            else
            {
                //filter on querystring
                if (Request.QueryString["status"] == "active")
                {
                    if (user.IsApproved && !user.IsLockedOut)
                    {
                        filteredUsers.Add(user);
                        count++;
                    }
                }
                else if (Request.QueryString["status"] == "inactive")
                {
                    if (!user.IsApproved && !user.IsLockedOut)
                    {
                        filteredUsers.Add(user);
                        count++;
                    }
                }
                else if (Request.QueryString["status"] == "locked")
                {
                    if (user.IsLockedOut)
                    {
                        filteredUsers.Add(user);
                        count++;
                    }
                }
                else if (Request.QueryString["status"] == "online")
                {
                    if (user.IsOnline)
                    {
                        filteredUsers.Add(user);
                        count++;
                    }
                }
                else if (Request.QueryString["status"] == "notverified")
                {
                    if (user.IsApproved && !userProfile.IsVerified)
                    {
                        filteredUsers.Add(user);
                        count++;
                    }
                }
                else
                {
                    filteredUsers.Add(user);
                    count++;
                }
            }
        }
    }

    GridView1.DataSource = filteredUsers;
    GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    BindGrid();
}

and the .aspx page…

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="1000px" onrowdatabound="GridView1_RowDataBound" ViewStateMode="Enabled" AllowPaging="True" onpageindexchanging="GridView1_PageIndexChanging" PageSize="25">
                <Columns>
                    <asp:TemplateField ItemStyle-Width="70px">
                        <ItemTemplate>
                            <asp:HyperLink ID="lnkProfile" runat="server"><asp:Image ID="Image3" runat="server" ImageUrl="~/Content/admin_miniProfile.png" AlternateText="User Profile" /></asp:HyperLink>
                            &nbsp;<asp:HyperLink ID="lnkPermissions" runat="server"><asp:Image ID="Image2" runat="server" ImageUrl="~/Content/admin_miniPermissions.png" AlternateText="Permissions" /></asp:HyperLink>
                            &nbsp;<asp:HyperLink ID="lnkPassword" runat="server"><asp:Image ID="Image1" runat="server" ImageUrl="~/Content/admin_miniResetPassword.png" AlternateText="Reset Password" /></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>                        
                    <asp:BoundField DataField="UserName" HeaderText="User Name" />
                    <asp:TemplateField ItemStyle-Width="100px" HeaderText="Account No">
                        <ItemTemplate>                                
                            <asp:Label ID="lblAccountNo" runat="server" Text=""></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>                        
                    <asp:BoundField DataField="CreationDate" HeaderText="Created" ItemStyle-Width="160px" />
                    <asp:TemplateField ItemStyle-Width="20px">
                        <ItemTemplate>
                            <asp:HyperLink ID="lnkSalesman" runat="server"><asp:Image ID="imgFilter" runat="server" ImageUrl="~/Content/admin_miniFilter.png" /></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ItemStyle-Width="200px" HeaderText="Salesman">
                        <ItemTemplate>                                
                            <asp:Label ID="lblSalesman" runat="server" Text=""></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField ItemStyle-Width="20px">
                        <ItemTemplate>
                            <asp:HyperLink ID="lnkDelete" runat="server"><asp:Image ID="Image4" runat="server" ImageUrl="~/Content/admin_miniDeleteUser.png" AlternateText="Delete User" /></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>    
                <PagerSettings Position="TopAndBottom" />
                <RowStyle Height="20px" VerticalAlign="Middle" />        
                <AlternatingRowStyle BackColor="#EEEEEE" />        
            </asp:GridView>

Everything is working fine except for the paging.

Can anyone help me? Please let me know if i’ve missed any important info and i’ll update!!

  • 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-06-14T17:23:31+00:00Added an answer on June 14, 2026 at 5:23 pm

    I’ve sorted it!

    I’ve put the collection into the session on the page load and bound the gridview datasource to the session object. Only creating the session object when not a postback.

    updated code works…

    protected void Page_Load(object sender, EventArgs e)
    {
        count = 0;             
    
        switch (Request.QueryString["status"])
        {
            case "active":
                lblUserListTitle.Text = "Activated user accounts";
                break;
            case "inactive":
                lblUserListTitle.Text = "Inactive user accounts";
                break;
            case "locked":
                lblUserListTitle.Text = "Locked user accounts";
                break;
            case "online":
                lblUserListTitle.Text = "Users online";
                break;
            case "notverified":
                lblUserListTitle.Text = "Users accounts not yet verified";
                break;
            default:
                lblUserListTitle.Text = "All user accounts";
                break;
        }
    
        if (!IsPostBack)
        {
            MembershipUserCollection usersList = Membership.GetAllUsers();
            MembershipUserCollection filteredUsers = new MembershipUserCollection();
    
            foreach (MembershipUser user in usersList)
            {
                if (!Roles.IsUserInRole(user.UserName, "Admin") && !Roles.IsUserInRole(user.UserName, "Engineering"))
                {
                    userProfile = Profile.GetProfile(user.UserName);
    
                    if (txtFilterCustomerNo.Text.Length > 0)
                    {
                        ProfileCommon PC = Profile.GetProfile(user.UserName);
                        if (PC.RaymarineAccountNo == txtFilterCustomerNo.Text.ToUpper())
                        {
                            filteredUsers.Add(user);
                            count++;
                        }
                    }
                    else
                    {
                        //filter on querystring
                        if (Request.QueryString["status"] == "active")
                        {
                            if (user.IsApproved && !user.IsLockedOut)
                            {
                                filteredUsers.Add(user);
                                count++;
                            }
                        }
                        else if (Request.QueryString["status"] == "inactive")
                        {
                            if (!user.IsApproved && !user.IsLockedOut)
                            {
                                filteredUsers.Add(user);
                                count++;
                            }
                        }
                        else if (Request.QueryString["status"] == "locked")
                        {
                            if (user.IsLockedOut)
                            {
                                filteredUsers.Add(user);
                                count++;
                            }
                        }
                        else if (Request.QueryString["status"] == "online")
                        {
                            if (user.IsOnline)
                            {
                                filteredUsers.Add(user);
                                count++;
                            }
                        }
                        else if (Request.QueryString["status"] == "notverified")
                        {
                            if (user.IsApproved && !userProfile.IsVerified)
                            {
                                filteredUsers.Add(user);
                                count++;
                            }
                        }
                        else
                        {
                            filteredUsers.Add(user);
                            count++;
                        }
                    }
                }
            }
    
            if (Session["FilteredUsers"] == null)
                Session.Add("FilteredUsers", new MembershipUserCollection());
            Session["FilteredUsers"] = filteredUsers;
        }
    
        BindGrid();    
    
        lblSearchResult.Text = "There are " + count.ToString() + " registered users found.";
    }
    protected void BindGrid()
    {    
    
        GridView1.DataSource = (MembershipUserCollection)Session["FilteredUsers"];
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindGrid();
    }
    

    if there is a better way than this, please do say, im still learning asp.net/c#!!

    thanks

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

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I am currently running into a problem where an element is coming back from

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.