473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Custom Paging with a dataset?

OK, im really lost and really hoping you experts can help me. I have a datagrid that is bound by a dataset. I have paging enabled and 5 per page. So far everything works, untill you go to view the second, third, etc page. Then it stops. From what I understand, I need to tell it to pull teh data from the dataset. How do I do this?
Jul 10 '06 #1
1 5591
sashi
1,754 Expert 1GB
hi there,

pls refer to the below sample code.. good luck my fren.. :)

DataGrid Paging
Expand|Select|Wrap|Line Numbers
  1. <%@ Import Namespace="System.Data" %>
  2. <%@ Import Namespace="System.Data.SqlClient" %>
  3. <html>
  4. <head>
  5.  <title>DotNetJunkies.com - Paging in the DataGrid Part 1</title>
  6.  <script runat="server" language="VB">
  7.   Sub Page_Load(Source As Object, E As EventArgs)
  8.    If Not Page.IsPostBack Then
  9.     BindData()
  10.    End If
  11.   End Sub
  12.  
  13.   Sub BindData()
  14.    Dim ds As New DataSet
  15.    Dim sda As SqlDataAdapter
  16.    Dim strSQL As String
  17.    Dim strCon As String
  18.  
  19.    strSQL = "SELECT CompanyName, ContactName, " & _
  20.      " ContactTitle, Phone, Fax FROM Customers " & _
  21.      " ORDER BY CompanyName" < BR>   strCon="server=localhost;database=Northwind;uid=sa;pwd=;"
  22.  
  23.    sda = New SqlDataAdapter(strSQL, strCon)
  24.    sda.Fill(ds, "Customers")
  25.  
  26.    myDataGrid.DataSource = ds.Tables("Customers")
  27.    myDataGrid.DataBind()
  28.   End Sub
  29.  
  30.   Sub myDataGrid_PageChanger(Source As Object, _
  31.                    E As DataGridPageChangedEventArgs)
  32.    ' Set the CurrentPageIndex before binding the grid 
  33.    myDataGrid.CurrentPageIndex = E.NewPageIndex 
  34.    BindData() 
  35.   End Sub
  36.  </script>
  37.  <style>
  38.   .DataGrid {font:x-small Verdana, Arial, sans-serif}
  39.  </style>
  40. </head>
  41. <body>
  42. <form runat="server" method="post"> 
  43.   <asp:DataGrid runat="server" id="myDataGrid" 
  44.     Border="0" 
  45.     Cellpadding="4" 
  46.     Cellspacing="0" 
  47.     AlternatingItemStyle-BackColor="#EFEFEF" 
  48.     ShowHeader="True" 
  49.     CssClass="DataGrid" 
  50.     HeaderStyle-BackColor="Black" 
  51.     HeaderStyle-ForeColor="White" 
  52.     HeaderStyle-Font-Bold="True" 
  53.     AllowPaging="True" 
  54.     PageSize="10" 
  55.     PagerStyle-Mode="NumericPages" 
  56.     OnPageIndexChanged="myDataGrid_PageChanger" 
  57.   /> 
  58. </form>
  59. </body>
  60. </html>
  61.  
Using NextPrev on a DataGrid
Expand|Select|Wrap|Line Numbers
  1. <%@ Import Namespace="System.Data" %>
  2. <%@ Import Namespace="System.Data.SqlClient" %>
  3. <html>
  4. <head>
  5.  <title>DotNetJunkies.com - Paging in the DataGrid Part 1</title>
  6.  <script runat="server" language="VB">
  7.   Sub Page_Load(Source As Object, E As EventArgs)
  8.    If Not Page.IsPostBack Then
  9.     BindData()
  10.    End If
  11.   End Sub
  12.  
  13.   Sub BindData()
  14.    Dim ds As New DataSet
  15.    Dim sda As SqlDataAdapter
  16.    Dim strSQL As String
  17.    Dim strCon As String
  18.  
  19.    strSQL = "SELECT CompanyName, ContactName, " & _
  20.      " ContactTitle, Phone, Fax FROM Customers " & _
  21.      " ORDER BY CompanyName" < BR>   strCon="server=localhost;database=Northwind;uid=sa;pwd=;"
  22.  
  23.    sda = New SqlDataAdapter(strSQL, strCon)
  24.    dsc.Fill(ds, "Customers")
  25.  
  26.    myDataGrid.DataSource = ds.Tables("Customers").DefaultView
  27.    myDataGrid.DataBind()
  28.   End Sub
  29.  
  30.   Sub myDataGrid_PageChanger(Source As Object, _
  31.                    E As DataGridPageChangedEventArgs)
  32.    ' Set the CurrentPageIndex before binding the grid 
  33.    myDataGrid.CurrentPageIndex = E.NewPageIndex 
  34.    BindData() 
  35.   End Sub
  36.  </script>
  37.  <style>
  38.   .DataGrid {font:x-small Verdana, Arial, sans-serif}
  39.  </style>
  40. </head>
  41. <body>
  42. <form runat="server" method="post">
  43.  <asp:DataGrid runat="server" id="myDataGrid"
  44.    Border="0"
  45.    Cellpadding="4"
  46.    Cellspacing="0"
  47.    AlternatingItemStyle-BackColor="#EFEFEF"
  48.    ShowHeader="True"
  49.    CssClass="DataGrid"
  50.    HeaderStyle-BackColor="Black"
  51.    HeaderStyle-ForeColor="White"
  52.    HeaderStyle-Font-Bold="True"
  53.    AllowPaging="True"
  54.    PageSize="10"
  55.    PagerStyle-Mode="NextPrev"
  56.    PagerStyle-NextPageText="Next -&gt;"
  57.    PagerStyle-PrevPageText="&lt;- Previous"
  58.    PagerStyle-Font-Bold="True"
  59.    OnPageIndexChanged="myDataGrid_PageChanger"
  60.  />
  61. </form>
  62. </body>
  63. </html>
  64.  
Jul 10 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dave S | last post by:
Hi, I'm using a datagrid to display contents of a dataset and I've set the datagrid to allow paging and sorting. Rather than re-retrieve from the DB, I store the original dataset in a Session...
1
by: Paul Hobbs | last post by:
Hi Everyone, I am trying to implement a DataGrid that uses Custom paging, but the DataSource is a SQLDataReader, not a DataSet. I have seen examples that use the Fill method of a DataAdapter to...
1
by: Joseph D. DeJohn | last post by:
Hello, I'm trying to implement custom paging. At the moment I can get the first page to display. When I click on the number 2 it takes forever to come back to the Page_Load function. I am...
2
by: Brian K. Williams | last post by:
Does anyone know how I can pass data to a Custom Web Control? I have been able to pass a DataSet as an object but I can't use it. DataSets don't seem to be available the namespaces will not load. ...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
2
by: farhad13841384 | last post by:
Hi , I Hope You fine. I have some problem with this code for paging in asp.net this bottom code work correctly without any error but when I try to place separate code in .VB file then error is...
7
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla,...
0
JustRun
by: JustRun | last post by:
Hi, This is the first time to work with ASP.NET. I had a customized membership gridview, the problem is i can't enable paging feature or sorting. 1 protected DataSet MyGetAllUsers() 2 ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.