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. General Programming
  3. C#
  4. Paging in Datagrid

Paging in Datagrid

Scheduled Pinned Locked Moved C#
question
2 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.
  • S Offline
    S Offline
    skrishnasarma
    wrote on last edited by
    #1

    I wiold like to do paging say by 1 , 2, 3 or next/Previous in datagrid (In Win form application) Any Input or Sample code please?

    W 1 Reply Last reply
    0
    • S skrishnasarma

      I wiold like to do paging say by 1 , 2, 3 or next/Previous in datagrid (In Win form application) Any Input or Sample code please?

      W Offline
      W Offline
      WillemM
      wrote on last edited by
      #2

      It would ask a lot of work, but you can do the following: Create two datasets, one dataset has all the data, the second one only has the records to view (one page at a time). page = 30 records (begins at 0) beginrecord = page * 30 endrecord = (page * 30) + 30 Every time you go to the next or previous page execute the following procedure for the new page (clear the view dataset first):

      //This code is an example probably doesnt work this way
      string configuredTable = "MyTable";
      DataSet myDataSet = new DataSet();

      for(int index = beginrecord; index < endrecord; index++)
      {
      DataRow newrow = viewdataset.Tables[configuredTable].NewRow();

      //TODO: Setup the data in the viewrow

      viewdataset.Tables[configuredTable].AddRow(newrow);
      }

      viewdataset.AcceptChanges();

      walk through the dataset table with the records you want to display and add them to a separate dataset. (Don't forget to call AcceptChanges()) There's one problem though: You should not edit the records in the view dataset, because that one gets cleared every time you change the page. Ofcourse you can implement the DataRowAdded eventhandler and add the same data to the non-view dataset. WM.
      What about weapons of mass-construction?

      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