Default Paging with the DataGrid Demo

This demo shows how to configure the DataGrid to support default paging. In future live demos we'll see how to customize the navigational interface.

2How do you convert a string to all uppercase or all lowercase?
7How do I dynamically resize an array?
8How do you create a database table through a SQL statement (via an ASP page, perhaps)?
10How can I tell what version of ADO I am using?
11How can I have my ASP page send HTML-formatted email?
12How can I display line breaks in an email message?
13How do you send email attachments through an ASP page?
14Can I send emails without using CDONTS?
15How can I determine the length of a string (how many characters are in a string)?
16Using VBScript, how can I determine if a variable is a valid date or not?
<-- Prev. Next -->

Source Code
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
  End Sub
  Sub BindData()
    '1. Create a connection
    Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))

    '2. Create the command object, passing in the SQL string
    Const strSQL as String = "SELECT FAQID, Description FROM tblFAQs ORDER BY FAQID"
    Dim myCommand as New SqlCommand(strSQL, myConnection)

	Dim myAdapter as New SqlDataAdapter(myCommand)
	Dim ds as New DataSet()
    'Set the datagrid's datasource to the DataSet and databind    
    dgPopularFAQs.DataSource = ds
  End Sub
  Sub NewPage(sender As Object, e As DataGridPageChangedEventArgs) 
    dgPopularFAQs.CurrentPageIndex = e.NewPageIndex

  End Sub


<form runat="server">
	<asp:DataGrid runat="server" id="dgPopularFAQs" 
	                BackColor="#eeeeee" Width="85%"
	  <HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" />
	  <AlternatingItemStyle BackColor="White" />
	  <PagerStyle NextPageText="Next --&gt;" PrevPageText="&lt;-- Prev."
	             HorizontalAlign="Right" />

[Return to the article]