c# - Gridview sort reveals far more than anticipated! -
I need some help here, I am currently making goals in the circle.
I have a gridview
protected void btnSubmit_Click (object sender, EventArgs e) {if (radTopx.SelectedValue == "" || txtbxHowMany.Text == "" : That a radio button is filled with item based on the selection of the item) {MessageBox.Show ("Please make sure that both the 'appropriate number of product' is selected and selected before you run X Effort "," Top X Error !!! ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); GridView1.DataSourceID = Faucet; GridView1.DataBind (); } And {int max = 0; If (int.TryParse (maximize txtbxHowMany.Text, outside)) {GridView1.DataSource = this.GetMaterialData (session "[MemberKey"] toString (), radTopx.SelectedItem.Value, "Primary", Max.); GridView1.DataSourceID = string.opt; GridView1.DataBind (); }}}
Where is GetMaterialData code:
Private Object GetMaterialData (String MemberKey, String MaterialType, String MaterialLevel, Calculate Integer) {ORWeightsDataClassesDataContext db = New ORWeightsDataClassesDataContext (); On query = db.tblOnlineReportingCOMPLETEWeights .Where (x => x.MemberId == MemberKey & amp; x.MaterialText == MaterialType & amp; x.MaterialLevel == MaterialLevel) .OderByDescending (X = & Gt; x.ProductPercentage). (Calculation); Return query; }
When it's run in the first example, it's running fine and okay ... good.
However, when I try to sort the gridview, the data changes and returns to bring all data set from its data source.
here html & amp; Back to code for # gridview:
& lt; ASP: GridView id = "GridView1" runat = "server" AutoGenerateColumns = "false" style = "z-index: 1; left: 215px; top: 560px; condition: full; height: 133px; width: 755px ; Text-line: center; "font-size =" x-small "onpageindexchanging =" GridView1_PageIndexChanging "onsorting =" GridView1_Sorting "Allow Paging =" True "AllowSorting =" True "& gt; Protected Zero GridView1_PageIndexChanging (Object Sender, GridViewPageEventArgs E) {GridView1.PageIndex = e.NewPageIndex; GridView1.DataSourceID = "lqPackWeights"; GridView1.DataBind (); } Secure Zero GridView1_Sorting (Object Sender, GridViewSortEventArgs E) {GridView1.DataSourceID = "lqPackWeights"; GridView1.DataBind (); } Anyone have any idea how can I make sure that when the gridwave is sorted, the original viewstrate is maintained?
You need a check in both your GridView 1_PageIndexChanging and GridView1_Sorting functions, to see if The user has done anything with the Radtext x or txtbxHowMany. If so, you will use the return value of GetMaterialData (), otherwise you will use "lqPackWeights" DataSourceID.
So you need everyone, it only takes a little more code to handle all the different situations that may arise.
Comments
Post a Comment