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?
1 5591
hi there,
pls refer to the below sample code.. good luck my fren.. :)
DataGrid Paging -
<%@ Import Namespace="System.Data" %>
-
<%@ Import Namespace="System.Data.SqlClient" %>
-
<html>
-
<head>
-
<title>DotNetJunkies.com - Paging in the DataGrid Part 1</title>
-
<script runat="server" language="VB">
-
Sub Page_Load(Source As Object, E As EventArgs)
-
If Not Page.IsPostBack Then
-
BindData()
-
End If
-
End Sub
-
-
Sub BindData()
-
Dim ds As New DataSet
-
Dim sda As SqlDataAdapter
-
Dim strSQL As String
-
Dim strCon As String
-
-
strSQL = "SELECT CompanyName, ContactName, " & _
-
" ContactTitle, Phone, Fax FROM Customers " & _
-
" ORDER BY CompanyName" < BR> strCon="server=localhost;database=Northwind;uid=sa;pwd=;"
-
-
sda = New SqlDataAdapter(strSQL, strCon)
-
sda.Fill(ds, "Customers")
-
-
myDataGrid.DataSource = ds.Tables("Customers")
-
myDataGrid.DataBind()
-
End Sub
-
-
Sub myDataGrid_PageChanger(Source As Object, _
-
E As DataGridPageChangedEventArgs)
-
' Set the CurrentPageIndex before binding the grid
-
myDataGrid.CurrentPageIndex = E.NewPageIndex
-
BindData()
-
End Sub
-
</script>
-
<style>
-
.DataGrid {font:x-small Verdana, Arial, sans-serif}
-
</style>
-
</head>
-
<body>
-
<form runat="server" method="post">
-
<asp:DataGrid runat="server" id="myDataGrid"
-
Border="0"
-
Cellpadding="4"
-
Cellspacing="0"
-
AlternatingItemStyle-BackColor="#EFEFEF"
-
ShowHeader="True"
-
CssClass="DataGrid"
-
HeaderStyle-BackColor="Black"
-
HeaderStyle-ForeColor="White"
-
HeaderStyle-Font-Bold="True"
-
AllowPaging="True"
-
PageSize="10"
-
PagerStyle-Mode="NumericPages"
-
OnPageIndexChanged="myDataGrid_PageChanger"
-
/>
-
</form>
-
</body>
-
</html>
-
Using NextPrev on a DataGrid -
<%@ Import Namespace="System.Data" %>
-
<%@ Import Namespace="System.Data.SqlClient" %>
-
<html>
-
<head>
-
<title>DotNetJunkies.com - Paging in the DataGrid Part 1</title>
-
<script runat="server" language="VB">
-
Sub Page_Load(Source As Object, E As EventArgs)
-
If Not Page.IsPostBack Then
-
BindData()
-
End If
-
End Sub
-
-
Sub BindData()
-
Dim ds As New DataSet
-
Dim sda As SqlDataAdapter
-
Dim strSQL As String
-
Dim strCon As String
-
-
strSQL = "SELECT CompanyName, ContactName, " & _
-
" ContactTitle, Phone, Fax FROM Customers " & _
-
" ORDER BY CompanyName" < BR> strCon="server=localhost;database=Northwind;uid=sa;pwd=;"
-
-
sda = New SqlDataAdapter(strSQL, strCon)
-
dsc.Fill(ds, "Customers")
-
-
myDataGrid.DataSource = ds.Tables("Customers").DefaultView
-
myDataGrid.DataBind()
-
End Sub
-
-
Sub myDataGrid_PageChanger(Source As Object, _
-
E As DataGridPageChangedEventArgs)
-
' Set the CurrentPageIndex before binding the grid
-
myDataGrid.CurrentPageIndex = E.NewPageIndex
-
BindData()
-
End Sub
-
</script>
-
<style>
-
.DataGrid {font:x-small Verdana, Arial, sans-serif}
-
</style>
-
</head>
-
<body>
-
<form runat="server" method="post">
-
<asp:DataGrid runat="server" id="myDataGrid"
-
Border="0"
-
Cellpadding="4"
-
Cellspacing="0"
-
AlternatingItemStyle-BackColor="#EFEFEF"
-
ShowHeader="True"
-
CssClass="DataGrid"
-
HeaderStyle-BackColor="Black"
-
HeaderStyle-ForeColor="White"
-
HeaderStyle-Font-Bold="True"
-
AllowPaging="True"
-
PageSize="10"
-
PagerStyle-Mode="NextPrev"
-
PagerStyle-NextPageText="Next ->"
-
PagerStyle-PrevPageText="<- Previous"
-
PagerStyle-Font-Bold="True"
-
OnPageIndexChanged="myDataGrid_PageChanger"
-
/>
-
</form>
-
</body>
-
</html>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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.
...
|
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
|
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...
|
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...
|
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,...
|
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 ...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |