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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:00:24+00:00 2026-05-13T02:00:24+00:00

I need some help here, I’m currently going round in circles. I have a

  • 0

I need some help here, I’m currently going round in circles.

I have a gridview that is populated based upon a radio button item selected :

protected void btnSubmit_Click(object sender, EventArgs e)
{

    if (radTopx.SelectedValue == "" || txtbxHowMany.Text == "")
    {
        MessageBox.Show("Please Ensure that BOTH 'The Number of Products' and Appropriate material Is selected Before You Attempt To Run a TOP x Report", "Top x Error!!!",
             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        GridView1.DataSourceID = null;
        GridView1.DataBind();
    }

    else
    {
        int max = 0;
        if (int.TryParse(txtbxHowMany.Text, out max))
        {

            GridView1.DataSource = this.GetMaterialData(Session["MemberKey"].ToString(), radTopx.SelectedItem.Value, "Primary", max);
            GridView1.DataSourceID = String.Empty;
            GridView1.DataBind();
        }
    }
}

Where the GetMaterialData code is:

private object GetMaterialData(string MemberKey, string MaterialType, string MaterialLevel, int Count)

{
    ORWeightsDataClassesDataContext db = new ORWeightsDataClassesDataContext();
    var query = db.tblOnlineReportingCOMPLETEWeights
                .Where(x => x.MemberId == MemberKey && x.MaterialText == MaterialType && x.MaterialLevel == MaterialLevel)
                .OrderByDescending(x => x.ProductPercentage)
                .Take(Count);
    return query;
}

When this is run in the first instance, this runs absolutely fine and is paged fine…lovely.

However, when I attempt to sort the gridview, the data changes and reverts back to bringing in all the data set from it’s data source.

Here is the html & c# code behind for the gridview:

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    style="z-index: 1; left: 215px; top: 560px; position: absolute; height: 133px; width: 755px; text-align: center;" 
           Font-Size="X-Small" 
            onpageindexchanging="GridView1_PageIndexChanging"  onsorting="GridView1_Sorting"    
            AllowPaging="True"  AllowSorting="True">


  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataSourceID = "lqPackWeights";
        GridView1.DataBind();

    }

    protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
    {
        GridView1.DataSourceID = "lqPackWeights";
        GridView1.DataBind();

    }

Anyone have any ideas how I can ensure that when the gridview is sorted, the original viewstate is maintained?

  • 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-13T02:00:24+00:00Added an answer on May 13, 2026 at 2:00 am

    You need to have a check in both your GridView1_PageIndexChanging and GridView1_Sorting functions to see if the user has done anything with radTopx or txtbxHowMany. If so, you would use the returned value of GetMaterialData(), otherwise you would use the DataSourceID of “lqPackWeights”.

    So you have everything you need, it just takes a little more code to handle all of the various situations that can arise.

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

Sidebar

Ask A Question

Stats

  • Questions 251k
  • Answers 251k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a few things that you can do to… May 13, 2026 at 9:34 am
  • Editorial Team
    Editorial Team added an answer Use an update with a join: set @rank := 0;… May 13, 2026 at 9:34 am
  • Editorial Team
    Editorial Team added an answer setVisibility() will allow you to make a widget visible, invisible,… May 13, 2026 at 9:34 am

Related Questions

I need some help here, I'm currently going round in circles. I have a
Guys i need some help here , im getting this error here at the
I am trying to optimize my MySQL queries and I need some help. Here
I'm having a hard time wrapping my head around this and need some help
I'm stuck here again. I have a database with over 120 000 coordinates that

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.