DataGrid Paging with Numeric Pages Demo

This demo illustrates how to use the numeric pages navigational interface with default paging.


FAQIDDescription
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?
1 2 3 4 5 6 7 8 9 10 ...


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)
    BindData()
  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()
	myAdapter.Fill(ds)
    
    'Set the datagrid's datasource to the DataSet and databind    
    dgPopularFAQs.DataSource = ds
    dgPopularFAQs.DataBind()	
    
    myConnection.Close()
  End Sub
  
  
  Sub NewPage(sender As Object, e As DataGridPageChangedEventArgs) 
    dgPopularFAQs.CurrentPageIndex = e.NewPageIndex

    BindData()      
  End Sub

</script>

<form runat="server">
	<asp:DataGrid runat="server" id="dgPopularFAQs" 
	                BackColor="#eeeeee" Width="85%"
	                HorizontalAlign="Center"
	                Font-Name="Verdana"
	                Font-Size="10pt"
	                AllowPaging="True"
	                OnPageIndexChanged="NewPage">
	  <HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True" HorizontalAlign="Center" />
	  <AlternatingItemStyle BackColor="White" />
	  <PagerStyle Mode="NumericPages" HorizontalAlign="Center" />
	</asp:datagrid>
</form>
	


[Return to the article]