1

Below is my jquery code to implement search filter for gridview along with paging,i am able to implement searching but the problem is in paging if i click edit button i am getting back to first page of my gridview instead of staying in that particular page.How to get stayed in that particular page on clicking edit button in gridview

                // DataTable
                //var table = $('#<%=GridView1.ClientID %>').DataTable({
                var table = $('#<%=GridView1.ClientID %>').prepend($('<thead></thead>').append($('#<%=GridView1.ClientID %>').find('tr:first'))).DataTable({
                    "paging": true,
                    "ordering": false,
                    "info": false,
                    "pageLength": 10,
                    "bLengthChange": false
                });

                table.columns().every(function () {
                    var that = this;

                    $('input', this.header()).on('keyup change', function () {
                        if (that.search() !== this.value) {
                            that
                                .search(this.value)
                                .draw();
                        }
                    });
                });
            });
xyz
  • 35
  • 5

2 Answers2

1

You can store your gridview data(from search) to Sessions and retrieve it when the edit function triggered and Maybe this link will help you? https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting(v=vs.110).aspx

     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
     {
          Session["PageIndex"] = e.NewPageIndex;
     }
     public void EditSubjectItem()
     {
          GridView1.PageIndex = Session["PageIndex"]
     }
Joseph
  • 653
  • 1
  • 12
  • 28
  • I had done in that way also but still it is taking me to first page on clicking edit button – xyz Jan 16 '17 at 07:14
  • Did you already try to set the page index after data binding the GridView? http://stackoverflow.com/questions/4991611/maintaining-gridview-current-page-index-after-navigating-away-from-gridview-page – Joseph Jan 16 '17 at 07:28
  • yes what i already have is gridview with paging to this what i did is i had implemented search filter for gridview now the search filter is working but the problem is let us assume i am in 5th page of gridview and i click edit/del button for any particular record out of 1 records in 5th page then what happens is i am getting back to first page instead of statying in 5th page this functionality is done by above posted jquery code – xyz Jan 16 '17 at 07:40
  • i had not tried it previously but i tried now but still it is taking me to first page if i click edit button from 5th page – xyz Jan 16 '17 at 09:15
  • Have you tried adding `GridView1.PageIndex = Session["PageIndex"]` in your page_load? – Joseph Jan 16 '17 at 09:21
  • yes i tried but i am not using pageindexing in c# or aspx page every thing i customized in the jquery only <%--AllowPaging="true" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="10">--%> – xyz Jan 16 '17 at 09:24
  • see the aspx page gridview code allow paging and onpageindexchanging is under comment we have done paging for gridview using jquery code which i posted at the starting – xyz Jan 16 '17 at 09:26
0

I think you can do it with help of asp.net Like this,Just enable the Allow paging in asp page and create event for PageIndexChanging and set page index and re bind the data.

<asp:GridView 
ID="grView" 
runat="server" 
AllowPaging="true" 
PageSize = "20" 
AutoGenerateColumns="false" 
OnPageIndexChanging="grView_PageIndexChanging" >  </asp:GridView >

void grView_PageIndexChanging(Object sender, GridViewPageEventArgs e) 
 {
  grView.DataSource = DB.Source();  
  grView.PageIndex = e.NewPageIndex; 
  grView.DataBind(); 
 }

OR

In edtit Button code you have to do this

      grView.DataSource = DB.Source();  
      grView.PageIndex = e.NewPageIndex; 
      grView.DataBind(); 
Abinash
  • 471
  • 3
  • 13
  • If i am doing in this way my jquery search is not working that is why we had customized paging and searching using jquery but the only problem that was left over is when i click edit or del button from any of the page i am going back to first page instead of staying in that particular page – xyz Jan 16 '17 at 09:31
  • try this grView.DataSource = DB.Source(); grView.PageIndex = e.NewPageIndex; grView.DataBind(); in edit button code. – Abinash Jan 16 '17 at 09:33