Here is a small example of the pagin in the datagrid. it will show the pagin in the form of page number at the bottom of the gird.
Here is a small example of the pagin in the datagrid. it will show the pagin in the form of page number at the bottom of the gird.
<%@ 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>
|
No responses found. Be the first to respond and make money from revenue sharing program.
|