Note that there are some explanatory texts on larger screens.

plurals
  1. POGridview sort reveals far more than anticipated!
    text
    copied!<p>I need some help here, I'm currently going round in circles.</p> <p>I have a gridview that is populated based upon a radio button item selected :</p> <pre><code>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(); } } } </code></pre> <p>Where the GetMaterialData code is:</p> <pre><code>private object GetMaterialData(string MemberKey, string MaterialType, string MaterialLevel, int Count) { ORWeightsDataClassesDataContext db = new ORWeightsDataClassesDataContext(); var query = db.tblOnlineReportingCOMPLETEWeights .Where(x =&gt; x.MemberId == MemberKey &amp;&amp; x.MaterialText == MaterialType &amp;&amp; x.MaterialLevel == MaterialLevel) .OrderByDescending(x =&gt; x.ProductPercentage) .Take(Count); return query; } </code></pre> <p>When this is run in the first instance, this runs absolutely fine and is paged fine...lovely.</p> <p>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.</p> <p>Here is the html &amp; c# code behind for the gridview:</p> <pre><code> &lt;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"&gt; 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(); } </code></pre> <p>Anyone have any ideas how I can ensure that when the gridview is sorted, the original viewstate is maintained?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload