הדף כולו
<%@ Page Language="VB" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) If Not Page.IsPostBack Then ' Databind the data grid on the first request only ' (on postback, rebind only in paging and sorting commands) BindGrid() End If End Sub Sub DataGrid_Page(Sender As Object, e As DataGridPageChangedEventArgs) DataGrid1.CurrentPageIndex = e.NewPageIndex BindGrid() End Sub Sub DataGrid_Sort(Sender As Object, e As DataGridSortCommandEventArgs) DataGrid1.CurrentPageIndex = 0 SortField = e.SortExpression BindGrid() End Sub '--------------------------------------------------------- ' ' Helpers ' ' use a property to keep track of the sort field, and ' save it in viewstate between postbacks Property SortField() As String Get Dim o As Object = ViewState("SortField") If o Is Nothing Then Return String.Empty End If Return CStr(o) End Get Set(ByVal Value As String) ViewState("SortField") = Value End Set End Property Sub BindGrid() ' TODO: update the ConnectionString value for your application Dim ConnectionString As String = "server=server;database=db;trusted_connection=true" Dim CommandText As String ' TODO: update the CommandText value for your application If SortField = String.Empty Then CommandText = "select * from view_ActiveUsers order by iUser_ID" Else CommandText = "select * from view_ActiveUsers order by " & SortField End If Dim myConnection As New SqlConnection(ConnectionString) Dim myCommand As New SqlDataAdapter(CommandText, myConnection) Dim ds As New DataSet() myCommand.Fill(ds) DataGrid1.DataSource = ds DataGrid1.DataBind() End Sub Sub updateRowSize(o As Object, e As eventargs) DataGrid1.PageSize=iRowSize.Text BindGrid() end sub </script> <html> <head> </head> <body style="FONT-FAMILY: arial"> <form runat="server"> <p> <asp:datagrid id="DataGrid1" runat="server" width="80%" CellSpacing="1" GridLines="None" CellPadding="3" BackColor="White" ForeColor="Black" OnPageIndexChanged="DataGrid_Page" PageSize="4" AllowPaging="true" OnSortCommand="DataGrid_Sort" AutoGenerateColumns="false"> <HeaderStyle font-bold="True" forecolor="White" backcolor="#4A3C8C"></HeaderStyle> <PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages"></PagerStyle> <ItemStyle backcolor="#DEDFDE"></ItemStyle> <Columns> <asp:BoundColumn HeaderText="Login name" DataField="cLogin_Name" SortField="cLogin_Name" /> <asp:BoundColumn HeaderText="Class" DataField="cClass_Name"/> <asp:BoundColumn HeaderText="First Name" DataField="cFirst_NAme"/> <asp:BoundColumn HeaderText="Last Login" DataField="dLAst_Login_Date"/> </Columns> </asp:datagrid> </p> <p> </p> <p> <asp:TextBox id="iRowSize" runat="server" Width="53px"></asp:TextBox> <asp:Button id="btnChangeRow" runat="server" Text="Change row size" onC