Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Paging in Data Grid

Paging in Data Grid

Scheduled Pinned Locked Moved ASP.NET
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Khan Bangash
    wrote on last edited by
    #1

    Hi All, I have paging property true in my Datagrid Page. Now ther is Search Creteria in that page.When I click on Search, the Records are Displayed. Now the Problem is that, For Example I have 10 Pages before Search, I got 2 Pages After Search. When I click on the Second Page, All the Pages are Displayed again, not only My Search Second Page. Any Idea. Thanks in Advance. Khan.

    J 1 Reply Last reply
    0
    • K Khan Bangash

      Hi All, I have paging property true in my Datagrid Page. Now ther is Search Creteria in that page.When I click on Search, the Records are Displayed. Now the Problem is that, For Example I have 10 Pages before Search, I got 2 Pages After Search. When I click on the Second Page, All the Pages are Displayed again, not only My Search Second Page. Any Idea. Thanks in Advance. Khan.

      J Offline
      J Offline
      JustChiragPatel
      wrote on last edited by
      #2

      hi Safecom.cn, how are you ? well your problem is nothing...your code is working fine, but you have not handle paging properly.. first make one PagedDatasource oblect... then in one DataTable get your search result....give that DataTable to PagedDataSource as Datasource... Now bing this PagedDataSource to your DataGrid.... then when you clcik on search, result will be saved in paged data source and then to datagrid..so now your datasource is only searched result. also set "Paging" property of PagedDataSource to "true"... try it..if not working then reply me..i will help you.. Bye have a nice day...

      Chirag Patel

      K 1 Reply Last reply
      0
      • J JustChiragPatel

        hi Safecom.cn, how are you ? well your problem is nothing...your code is working fine, but you have not handle paging properly.. first make one PagedDatasource oblect... then in one DataTable get your search result....give that DataTable to PagedDataSource as Datasource... Now bing this PagedDataSource to your DataGrid.... then when you clcik on search, result will be saved in paged data source and then to datagrid..so now your datasource is only searched result. also set "Paging" property of PagedDataSource to "true"... try it..if not working then reply me..i will help you.. Bye have a nice day...

        Chirag Patel

        K Offline
        K Offline
        Khan Bangash
        wrote on last edited by
        #3

        Thank u very much for Help. Here is my Load function Public Sub DgBound() Try If (Conn.State <> ConnectionState.Open) Then Conn.Open() End If strQry = "Select cust_order.order_id as order_id, cust_order.customer_id as cust_id, cust_order.order_date as order_date, customers.fname as fname, customers.lname as lname from cust_order, customers, cust_order_ship where cust_order.customer_id = customers.customer_id and cust_order.order_id = cust_order_ship.order_id" Command = New OleDbCommand With Command .Connection = Conn .CommandText = strQry .CommandType = CommandType.Text End With da = New OleDbDataAdapter(strQry, Conn) da.SelectCommand = Command ds = New DataSet da.Fill(ds, "cust") dgProfit.DataSource = ds dgProfit.DataBind() totalreclbl.Text = ds.Tables(0).Rows.Count Catch ex As Exception Response.Write(ex.ToString) Finally Conn.Close() End Try End Sub and Here is My Search Code Try If (Conn.State <> ConnectionState.Open) Then Conn.Open() End If strQry = "Select cust_order.order_id as order_id, cust_order.customer_id as cust_id, cust_order.order_date as order_date, customers.fname as fname, customers.lname as lname from cust_order, customers, cust_order_ship where cust_order.customer_id = customers.customer_id and cust_order.order_id = cust_order_ship.order_id and cust_order.order_date >=#" & ViewState("startDate") & "# and cust_order.order_date <=#" & ViewState("endDate") & "#" Command = New OleDbCommand With Command .Connection = Conn .CommandText = strQry .CommandType = CommandType.Text End With Command2 = New OleDbCommand(strQry, Conn) total = Command2.ExecuteReader() If Not total.Read() Then lblMsg.Visible = True Else lblMsg.Visible = False End If da = New OleDbDataAdapter(strQry, Conn) da.SelectCommand = Command ds = New DataSet da.Fill(ds) dgProfit.CurrentPageIndex = 0 dgProfit.DataSource = ds totalreclbl.Text = ds.Tables(0).Rows.Count dgProfit.DataBind()

        K 1 Reply Last reply
        0
        • K Khan Bangash

          Thank u very much for Help. Here is my Load function Public Sub DgBound() Try If (Conn.State <> ConnectionState.Open) Then Conn.Open() End If strQry = "Select cust_order.order_id as order_id, cust_order.customer_id as cust_id, cust_order.order_date as order_date, customers.fname as fname, customers.lname as lname from cust_order, customers, cust_order_ship where cust_order.customer_id = customers.customer_id and cust_order.order_id = cust_order_ship.order_id" Command = New OleDbCommand With Command .Connection = Conn .CommandText = strQry .CommandType = CommandType.Text End With da = New OleDbDataAdapter(strQry, Conn) da.SelectCommand = Command ds = New DataSet da.Fill(ds, "cust") dgProfit.DataSource = ds dgProfit.DataBind() totalreclbl.Text = ds.Tables(0).Rows.Count Catch ex As Exception Response.Write(ex.ToString) Finally Conn.Close() End Try End Sub and Here is My Search Code Try If (Conn.State <> ConnectionState.Open) Then Conn.Open() End If strQry = "Select cust_order.order_id as order_id, cust_order.customer_id as cust_id, cust_order.order_date as order_date, customers.fname as fname, customers.lname as lname from cust_order, customers, cust_order_ship where cust_order.customer_id = customers.customer_id and cust_order.order_id = cust_order_ship.order_id and cust_order.order_date >=#" & ViewState("startDate") & "# and cust_order.order_date <=#" & ViewState("endDate") & "#" Command = New OleDbCommand With Command .Connection = Conn .CommandText = strQry .CommandType = CommandType.Text End With Command2 = New OleDbCommand(strQry, Conn) total = Command2.ExecuteReader() If Not total.Read() Then lblMsg.Visible = True Else lblMsg.Visible = False End If da = New OleDbDataAdapter(strQry, Conn) da.SelectCommand = Command ds = New DataSet da.Fill(ds) dgProfit.CurrentPageIndex = 0 dgProfit.DataSource = ds totalreclbl.Text = ds.Tables(0).Rows.Count dgProfit.DataBind()

          K Offline
          K Offline
          Khan Bangash
          wrote on last edited by
          #4

          I works fine. But After Search When I click on a page, All the pages are loaded again. I need only search result pages, after search .

          J 1 Reply Last reply
          0
          • K Khan Bangash

            I works fine. But After Search When I click on a page, All the pages are loaded again. I need only search result pages, after search .

            J Offline
            J Offline
            JustChiragPatel
            wrote on last edited by
            #5

            hi ... your problem is like ...your code is loading datagrid with total result..because ithink you have not write that "Public Sub DgBound()" function in "Page_Load" event... you should wirite page_load(...) { if(!Page.IsPostBack) { //then here you can call "Public Sub DgBound()" function... } } amd in search button click event write your search code... do remember use Dataset and datatable static and declare them public and globally...and use only one dataset or datatable to bing in "Public Sub DgBound()" function as well as in "Search" code... try this.. bye..

            Chirag Patel

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups