ASP.net 2.0 自定义控件的开发之数据分页 第五章

80酷酷网    80kuku.com

  asp.net|分页|控件|数据

新建一个 网站

将控件添加到工具箱中,在工具箱中点击鼠标右键,点选 选择项 菜单,然后在弹出的对话框中点击浏览按钮,找到编译后的 SqlPaging.dll 最后点击确定按钮即可。


新建一个 Default2.aspx 页面 然后在页面中添加控件 GridView Datalist  各一个 添加两个 SqlPaging 控件 添加一个按钮控件如下图

然后设置 SqlPaging 控件的两个重要的属性如下图




 
下面是控件的测试页面 default2.aspx 文件的html源码

<%... Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<%... Register Assembly="SqlPaging" Namespace="DRMSystem.DataLayer" TagPrefix="drmsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
 </div>
        
<table border="0" cellpadding="0" cellspacing="0" width="100%">
            
<tr>
                
<td style="height: 125px">
                    GridView Sample
<br />
                    
<br />
                    
<asp:GridView ID="GridView1" runat="server" Width="100%">
                    
</asp:GridView>
                    
  <br />
                    
<drmsp:SqlPaging ID="SqlPaging1" runat="server" StoredProcedureName="sys_QuickSortPaging" ControlToPaginate="GridView1" />
                
</td>
            
</tr>
            
<tr>
                
<td style="height: 29px">
                    
 
                
</td>
            
</tr>
            
<tr>
                
<td style="height: 361px">
                    DataList Sample
<br />
                    
<br />
                    
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal" HorizontalAlign="Justify" RepeatLayout="Flow" Width="100%">
                        
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                        
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                        
<AlternatingItemStyle BackColor="#F7F7F7" />
                        
<ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                        
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
                        
<ItemTemplate>
                            
<%...#DataBinder.Eval(Container.DataItem, "EmployeesID")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "LastName")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "FirstName")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "BirthDate")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "Address")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "City")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "HomePhone")%>
                            
<%...#DataBinder.Eval(Container.DataItem, "Extension")%>
                        
</ItemTemplate>
                    
</asp:DataList><br />
                    
<drmsp:SqlPaging ID="SqlPaging2" runat="server" ControlToPaginate="DataList1" StoredProcedureName="sys_QuickSortPaging" />
                    
<asp:Button ID="Button1" runat="server" Text="生成1百万条测试数据" />
                    更具硬件大约需要 5-20 分钟
</td>
            
</tr>
        
</table>
    
</form>
</body>
</html>

测试页 Default2.aspx.vb 源码

Imports System.Data
Imports System.Data.SqlClient

Partial Class Default2Class Default2
    
Inherits System.Web.UI.Page
    
'请更改Sql 数据库连接字符串的 DATABASE 部分

    
Private Const strSQlConn As String = "server=(local);Trusted_Connection=true;DATABASE=pubs;uid=sa"

    
Protected Sub Page_Load()Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load
        
If Not IsPostBack Then
            SqlPaging1.SQLConnection 
= strSQlConn
            SqlPaging1.PageInfoText_01 
= "每页"
            SqlPaging1.PageInfoText_02 
= "条记录"
            SqlPaging1.PageInfoText_03 
= "转到"
            SqlPaging1.PageInfoText_04 
= ""
            SqlPaging1.TableName 
= "Employees"
            SqlPaging1.PrimaryKeyField 
= "EmployeesID"
            SqlPaging1.Field 
= "*"
            SqlPaging1.DataBind()

            SqlPaging2.SQLConnection 
= strSQlConn
            SqlPaging2.PageInfoText_01 
= "每页"
            SqlPaging2.PageInfoText_02 
= "条记录"
            SqlPaging2.PageInfoText_03 
= "转到"
            SqlPaging2.PageInfoText_04 
= ""
            SqlPaging2.TableName 
= "Employees"
            SqlPaging2.PrimaryKeyField 
= "EmployeesID"
            SqlPaging2.Field 
= "*"
            SqlPaging2.Where 
= "EmployeesID<2000 And EmployeesID>1000"
            SqlPaging2.DataBind()
        
End If
    
End Sub



    
Protected Sub Button1_Click()Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles Button1.Click
        
Dim conn As New SqlConnection(strSQlConn)
        conn.Open()
        
Using conn
            
Dim Command As New SqlCommand
            
Command.Connection = conn
            
Command.CommandText = "InsertTableData"
            
Command.CommandTimeout = "600"
            
Command.CommandType = CommandType.StoredProcedure

            
Command.ExecuteNonQuery()
        
End Using

    
End Sub

End Class

代码下载

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: