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 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
  • 1 View
  • 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

Related Questions

i need some help here. I have a dialog box that contains an iFrame
I need some advanced CSS help here. I have a login button and a
Need some help to solve this. I have a gridview and inside the gridview
Need some help here. I have deployed spree (0.70.3) on slicehost (ubuntu, ruby1.8.7, Rails
I'm confused about how DQL works, and really need some help here. I have
Need some help, I have a regular expression that appears to work just fine
I need some help here, I have two questions regarding Qt's style sheet customization
Ok need some help here. I have an autocomplete setup to pull from a
I need some help here. I have a mysql table called dictionary like this:
I need some help here. Basically, I have an Activity. This uses the startActivityForResult()

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.