xyz
xyz

Reputation: 35

Paging doesn't work properly on clicking edit button in gridview using j query

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();
                        }
                    });
                });
            });

Upvotes: 1

Views: 734

Answers (2)

Abinash
Abinash

Reputation: 481

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(); 

Upvotes: 0

Joseph
Joseph

Reputation: 671

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"]
     }

Upvotes: 1

Related Questions