home *** CD-ROM | disk | FTP | other *** search
/ PC Active 2002 December / pca1412.iso / extra / aspnet / PageDataGrid.aspx < prev    next >
Encoding:
ASP.NET Web Form  |  2002-10-14  |  1.9 KB  |  53 lines

  1. <%@ Page Language="VB" Culture="nl-NL"%>
  2. <%@ import Namespace="System.Data" %>
  3. <%@ import Namespace="System.Data.SqlClient" %>
  4. <script runat="server">
  5.  
  6.     Dim ConnStr As String = "server=(local)\NetSdk;database=Northwind;trusted_connection=true"
  7.     Dim CommandStr As String = "SELECT ProductID, ProductName, UnitPrice FROM Products"
  8.     
  9.     Sub Page_Load(Sender As Object, E As EventArgs)
  10.        If Not Page.IsPostBack Then
  11.          BindGrid()
  12.        End If
  13.     End Sub
  14.     
  15.     Sub BindGrid()
  16.        Dim objConn As New SqlConnection(ConnStr)
  17.        Dim objCmnd As New SqlDataAdapter(CommandStr, objConn)
  18.        Dim objDs As New DataSet()
  19.     
  20.        objCmnd.Fill(objDs)
  21.     
  22.        Grid.DataSource = objDs
  23.        Grid.DataBind()
  24.     End Sub
  25.     
  26.     Sub ChangePage(source As Object, e As DataGridPageChangedEventArgs)
  27.         Grid.CurrentPageIndex = e.NewPageIndex
  28.         BindGrid()
  29.     End Sub
  30.  
  31. </script>
  32. <html>
  33. <head>
  34. </head>
  35. <body>
  36.     <form runat="server">
  37.         <asp:datagrid id="Grid" runat="server" AutoGenerateColumns="False" OnPageIndexChanged="ChangePage" AllowPaging="True" ForeColor="Black" BackColor="White" CellPadding="3" GridLines="None" CellSpacing="1">
  38.             <HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle>
  39.             <PagerStyle nextpagetext="volgende" prevpagetext="vorige" pagebuttoncount="5" mode="NumericPages"></PagerStyle>
  40.             <AlternatingItemStyle backcolor="#ABACAB"></AlternatingItemStyle>
  41.             <ItemStyle backcolor="#DEDFDE"></ItemStyle>
  42.             <Columns>
  43.               <asp:BoundColumn DataField="ProductName"
  44.                    HeaderText="Productnaam"/>
  45.               <asp:BoundColumn DataField="UnitPrice"
  46.                    HeaderText="Prijs" DataFormatString="{0:c}">
  47.               </asp:BoundColumn>
  48.             </Columns>
  49.         </asp:datagrid>
  50.     </form>
  51. </body>
  52. </html>
  53.