web 2.0

ASP.NET(vb.net) & DataGrid - AllowPaging/Pagination

ASP.NET(vb.net) & DataGrid - AllowPaging/Pagination Example scripts how to Explains DataGrid control in asp.net , The DataGrid.AllowPaging Gets or sets a value indicating whether the paging feature is enabled.

ShotDev Focus:
- ASP.NET(vb.net) & DataGrid - AllowPaging/Pagination

Example

DataGridAllowPaging.aspx


<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
IF Not Page.IsPostBack() Then
BindData()
End IF
End Sub

Sub BindData()

Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String

strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath("database/mydatabase.mdb")&";"
strSQL = "SELECT * FROM customer"

objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd

dtAdapter.Fill(ds)

'*** BindData to DataGrid ***'
myDataGrid.DataSource = ds
myDataGrid.DataBind()

dtAdapter = Nothing
objConn.Close()
objConn = Nothing

End Sub

Sub ShowPageCommand(sender As Object, e As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server" >
<asp:DataGrid id="myDataGrid" PageSize="2" OnPageIndexChanged="ShowPageCommand"
AllowPaging="True" runat="server">
<HeaderStyle BackColor="#cccccc"></HeaderStyle>
<AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>

Create a asp.net file and save to path root-path/dotnet/

Run
http://localhost/dotnet/DataGridAllowPaging.aspx

Screenshot

ASP.NET(vb.net) & DataGrid - AllowPaging/Pagination
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

One Response to “ASP.NET(vb.net) & DataGrid - AllowPaging/Pagination”

  1. 1trapping…

Leave a Reply

You must be logged in to post a comment.