datalist 分页的用户控件,我公司sunYun原创,如需转载,请联系作者
来源:互联网 发布:青岛太阳软件待遇 编辑:程序博客网 时间:2024/05/11 02:18
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<%@ Control Language="vb" AutoEventWireup="false" Codebehind="listControl.ascx.vb" Inherits="govoa.listControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录 当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页
<asp:LinkButton id="lblPrevious" runat="server" text="上一页"></asp:LinkButton>
<asp:LinkButton id="lblNext" runat="server" text="下一页"></asp:LinkButton>
<asp:DropDownList id="NumPerPage" runat="server" AutoPostBack="True">
<asp:ListItem Value="5">
5行/页</asp:ListItem>
<asp:ListItem Value="8" Selected="True">
8行/页</asp:ListItem>
<asp:ListItem Value="10">
10行/页</asp:ListItem>
<asp:ListItem Value="15">
15行/页</asp:ListItem>
<asp:ListItem Value="20">
20行/页</asp:ListItem>
<asp:ListItem Value="25">
25行/页</asp:ListItem>
<asp:ListItem Value="30">
30行/页</asp:ListItem>
<asp:ListItem Value="35">
35行/页</asp:ListItem>
<asp:ListItem Value="40">
40行/页</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtPage" Runat="server" Width="30"></asp:TextBox><asp:Button ID="btnGo" Runat="server" Text="转到"></asp:Button>
listControl.aspx.vb
Imports System.Data.SqlClient
Public MustInherit Class listControl
Inherits System.Web.UI.UserControl
Protected WithEvents lblRecordCount As System.Web.UI.WebControls.Label
Protected WithEvents lblCurrentPage As System.Web.UI.WebControls.Label
Protected WithEvents lblPageCount As System.Web.UI.WebControls.Label
Protected WithEvents lblPrevious As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblNext As System.Web.UI.WebControls.LinkButton
Protected WithEvents NumPerPage As System.Web.UI.WebControls.DropDownList
Protected WithEvents txtPage As System.Web.UI.WebControls.TextBox
Protected WithEvents btnGo As System.Web.UI.WebControls.Button
Private m_DataContainer As Repeater
Private m_datasource As String
Private m_toRefresh As Boolean = False
Private MyConn As SqlConnection
Private RecordCount, PageCount, CurrentPage As Integer
'/ <summary>
'/ 取得需要绑定的控件
'/ </summary>
Public Property GetRelatedControl() As Repeater
Get
Return m_DataContainer
End Get
Set(ByVal Value As Repeater)
m_DataContainer = Value
End Set
End Property
Public Property ToRefresh() As Boolean
Get
Return m_toRefresh
End Get
Set(ByVal Value As Boolean)
m_toRefresh = Value
End Set
End Property
Public Property GetRelatedSqlStr() As String
Get
Return m_datasource
End Get
Set(ByVal Value As String)
m_datasource = Value
If m_toRefresh Then
refreshData()
End If
End Set
End Property
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
MyConn = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
MyConn.Open()
ViewState("PageSize") = NumPerPage.SelectedItem.Value.ToString()
If Not Page.IsPostBack Then
BindControl()
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = Fix((RecordCount + Int32.Parse(NumPerPage.SelectedItem.Value)) / Convert.ToInt32(ViewState("PageSize").ToString())) - (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) <> 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
If PageCount <= 1 Then
lblNext.Enabled = False
End If
ViewState("PageCount") = PageCount
End If
End Sub
Private Sub refreshData()
MyConn = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
MyConn.Open()
ViewState("PageSize") = NumPerPage.SelectedItem.Value.ToString()
BindControl()
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = Fix((RecordCount + Int32.Parse(NumPerPage.SelectedItem.Value)) / Convert.ToInt32(ViewState("PageSize").ToString())) - (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) <> 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
If PageCount <= 1 Then
lblNext.Enabled = False
End If
ViewState("PageCount") = PageCount
End Sub
'/ <summary>
'/ 绑定控件
'/ </summary>
Private Sub BindControl()
m_DataContainer.DataSource = CreateSource()
m_DataContainer.DataBind()
'
lblNext.Enabled = True
lblPrevious.Enabled = True
If CurrentPage = PageCount - 1 Then
lblNext.Enabled = False
End If
If CurrentPage = 0 Then
lblPrevious.Enabled = False
End If
lblCurrentPage.Text = (CurrentPage + 1).ToString()
txtPage.Text = (CurrentPage + 1).ToString()
End Sub 'BindControl
'/ <summary>
'/ 产生datalist的DataView
'/ </summary>
'/ <returns></returns>
Private Function CreateSource() As DataView
Dim StartIndex As Integer
'设定导入的起终地址
StartIndex = CurrentPage * Convert.ToInt32(ViewState("PageSize").ToString()) '计算起始索引
Dim ds As New DataSet()
Dim MyAdapter As New SqlDataAdapter(m_datasource, MyConn)
MyAdapter.Fill(ds, StartIndex, Convert.ToInt32(ViewState("PageSize").ToString()), "Score")
Return ds.Tables("Score").DefaultView
End Function 'CreateSource
'/ <summary>
'/ 计算有多少记录
'/ </summary>
'/ <returns></returns>
Public Function CalculateRecord() As Integer
Dim ds As New DataSet()
Dim MyAdapter As New SqlDataAdapter(m_datasource, MyConn)
MyAdapter.Fill(ds, "tempTable")
Return ds.Tables("tempTable").DefaultView.Count
End Function 'CalculateRecord
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Try
Dim InputValue As Integer = Convert.ToInt32(txtPage.Text)
PageCount = CInt(ViewState("PageCount"))
If InputValue <= PageCount And InputValue > 0 Then
CurrentPage = Convert.ToInt32(txtPage.Text) - 1
Else
CurrentPage = CInt(ViewState("PageIndex"))
End If
ViewState("PageIndex") = CurrentPage
Catch
End Try
BindControl()
End Sub
Private Sub NumPerPage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumPerPage.SelectedIndexChanged
Try
ViewState("PageSize") = NumPerPage.SelectedItem.Value
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = RecordCount / Convert.ToInt32(ViewState("PageSize").ToString()) + (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) = 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
ViewState("PageCount") = PageCount
BindControl()
Catch
End Try
End Sub
Private Sub lblPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPrevious.Click
CurrentPage = CInt(ViewState("PageIndex"))
PageCount = CInt(ViewState("PageCount"))
If CurrentPage > 0 Then
CurrentPage -= 1
End If
ViewState("PageIndex") = CurrentPage
BindControl()
End Sub
Private Sub lblNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblNext.Click
CurrentPage = CInt(ViewState("PageIndex"))
PageCount = CInt(ViewState("PageCount"))
If CurrentPage < PageCount - 1 Then
CurrentPage += 1
End If
ViewState("PageIndex") = CurrentPage
BindControl()
End Sub
End Class
调用
自己看着办
几点说明:
这个是测试版本
掉用如下
ListControl1.GetRelatedControl = rptContent
ListControl1.ToRefresh = True
ListControl1.GetRelatedSqlStr = New bizlogic.DBFilm().selectFilmStr(ddl_Type.SelectedItem.Value, tbx_keyWord.Text)
如果有bug
请和 H.xue@163.net联系,多谢
一点说明:
我这里分页是repeater ,但是如果要用datalist也很容易,这个我就不说明了。大家一看就知道
datalist 分页的用户控件,我公司sunYun原创,如需转载,请联系作者';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
listControl.aspx<%@ Control Language="vb" AutoEventWireup="false" Codebehind="listControl.ascx.vb" Inherits="govoa.listControl" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录 当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页
<asp:LinkButton id="lblPrevious" runat="server" text="上一页"></asp:LinkButton>
<asp:LinkButton id="lblNext" runat="server" text="下一页"></asp:LinkButton>
<asp:DropDownList id="NumPerPage" runat="server" AutoPostBack="True">
<asp:ListItem Value="5">
5行/页</asp:ListItem>
<asp:ListItem Value="8" Selected="True">
8行/页</asp:ListItem>
<asp:ListItem Value="10">
10行/页</asp:ListItem>
<asp:ListItem Value="15">
15行/页</asp:ListItem>
<asp:ListItem Value="20">
20行/页</asp:ListItem>
<asp:ListItem Value="25">
25行/页</asp:ListItem>
<asp:ListItem Value="30">
30行/页</asp:ListItem>
<asp:ListItem Value="35">
35行/页</asp:ListItem>
<asp:ListItem Value="40">
40行/页</asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txtPage" Runat="server" Width="30"></asp:TextBox><asp:Button ID="btnGo" Runat="server" Text="转到"></asp:Button>
listControl.aspx.vb
Imports System.Data.SqlClient
Public MustInherit Class listControl
Inherits System.Web.UI.UserControl
Protected WithEvents lblRecordCount As System.Web.UI.WebControls.Label
Protected WithEvents lblCurrentPage As System.Web.UI.WebControls.Label
Protected WithEvents lblPageCount As System.Web.UI.WebControls.Label
Protected WithEvents lblPrevious As System.Web.UI.WebControls.LinkButton
Protected WithEvents lblNext As System.Web.UI.WebControls.LinkButton
Protected WithEvents NumPerPage As System.Web.UI.WebControls.DropDownList
Protected WithEvents txtPage As System.Web.UI.WebControls.TextBox
Protected WithEvents btnGo As System.Web.UI.WebControls.Button
Private m_DataContainer As Repeater
Private m_datasource As String
Private m_toRefresh As Boolean = False
Private MyConn As SqlConnection
Private RecordCount, PageCount, CurrentPage As Integer
'/ <summary>
'/ 取得需要绑定的控件
'/ </summary>
Public Property GetRelatedControl() As Repeater
Get
Return m_DataContainer
End Get
Set(ByVal Value As Repeater)
m_DataContainer = Value
End Set
End Property
Public Property ToRefresh() As Boolean
Get
Return m_toRefresh
End Get
Set(ByVal Value As Boolean)
m_toRefresh = Value
End Set
End Property
Public Property GetRelatedSqlStr() As String
Get
Return m_datasource
End Get
Set(ByVal Value As String)
m_datasource = Value
If m_toRefresh Then
refreshData()
End If
End Set
End Property
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
MyConn = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
MyConn.Open()
ViewState("PageSize") = NumPerPage.SelectedItem.Value.ToString()
If Not Page.IsPostBack Then
BindControl()
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = Fix((RecordCount + Int32.Parse(NumPerPage.SelectedItem.Value)) / Convert.ToInt32(ViewState("PageSize").ToString())) - (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) <> 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
If PageCount <= 1 Then
lblNext.Enabled = False
End If
ViewState("PageCount") = PageCount
End If
End Sub
Private Sub refreshData()
MyConn = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("ConnectionString"))
MyConn.Open()
ViewState("PageSize") = NumPerPage.SelectedItem.Value.ToString()
BindControl()
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = Fix((RecordCount + Int32.Parse(NumPerPage.SelectedItem.Value)) / Convert.ToInt32(ViewState("PageSize").ToString())) - (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) <> 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
If PageCount <= 1 Then
lblNext.Enabled = False
End If
ViewState("PageCount") = PageCount
End Sub
'/ <summary>
'/ 绑定控件
'/ </summary>
Private Sub BindControl()
m_DataContainer.DataSource = CreateSource()
m_DataContainer.DataBind()
'
lblNext.Enabled = True
lblPrevious.Enabled = True
If CurrentPage = PageCount - 1 Then
lblNext.Enabled = False
End If
If CurrentPage = 0 Then
lblPrevious.Enabled = False
End If
lblCurrentPage.Text = (CurrentPage + 1).ToString()
txtPage.Text = (CurrentPage + 1).ToString()
End Sub 'BindControl
'/ <summary>
'/ 产生datalist的DataView
'/ </summary>
'/ <returns></returns>
Private Function CreateSource() As DataView
Dim StartIndex As Integer
'设定导入的起终地址
StartIndex = CurrentPage * Convert.ToInt32(ViewState("PageSize").ToString()) '计算起始索引
Dim ds As New DataSet()
Dim MyAdapter As New SqlDataAdapter(m_datasource, MyConn)
MyAdapter.Fill(ds, StartIndex, Convert.ToInt32(ViewState("PageSize").ToString()), "Score")
Return ds.Tables("Score").DefaultView
End Function 'CreateSource
'/ <summary>
'/ 计算有多少记录
'/ </summary>
'/ <returns></returns>
Public Function CalculateRecord() As Integer
Dim ds As New DataSet()
Dim MyAdapter As New SqlDataAdapter(m_datasource, MyConn)
MyAdapter.Fill(ds, "tempTable")
Return ds.Tables("tempTable").DefaultView.Count
End Function 'CalculateRecord
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Try
Dim InputValue As Integer = Convert.ToInt32(txtPage.Text)
PageCount = CInt(ViewState("PageCount"))
If InputValue <= PageCount And InputValue > 0 Then
CurrentPage = Convert.ToInt32(txtPage.Text) - 1
Else
CurrentPage = CInt(ViewState("PageIndex"))
End If
ViewState("PageIndex") = CurrentPage
Catch
End Try
BindControl()
End Sub
Private Sub NumPerPage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NumPerPage.SelectedIndexChanged
Try
ViewState("PageSize") = NumPerPage.SelectedItem.Value
CurrentPage = 0
ViewState("PageIndex") = 0
'计算总共有多少记录
RecordCount = CalculateRecord()
lblRecordCount.Text = RecordCount.ToString()
'计算总共有多少页
PageCount = RecordCount / Convert.ToInt32(ViewState("PageSize").ToString()) + (IIf(RecordCount Mod Convert.ToInt32(ViewState("PageSize").ToString()) = 0, 0, 1)) 'ToDo: Unsupported feature: conditional (?) operator.
lblPageCount.Text = PageCount.ToString()
ViewState("PageCount") = PageCount
BindControl()
Catch
End Try
End Sub
Private Sub lblPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPrevious.Click
CurrentPage = CInt(ViewState("PageIndex"))
PageCount = CInt(ViewState("PageCount"))
If CurrentPage > 0 Then
CurrentPage -= 1
End If
ViewState("PageIndex") = CurrentPage
BindControl()
End Sub
Private Sub lblNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblNext.Click
CurrentPage = CInt(ViewState("PageIndex"))
PageCount = CInt(ViewState("PageCount"))
If CurrentPage < PageCount - 1 Then
CurrentPage += 1
End If
ViewState("PageIndex") = CurrentPage
BindControl()
End Sub
End Class
调用
自己看着办
几点说明:
这个是测试版本
掉用如下
ListControl1.GetRelatedControl = rptContent
ListControl1.ToRefresh = True
ListControl1.GetRelatedSqlStr = New bizlogic.DBFilm().selectFilmStr(ddl_Type.SelectedItem.Value, tbx_keyWord.Text)
如果有bug
请和 H.xue@163.net联系,多谢
一点说明:
我这里分页是repeater ,但是如果要用datalist也很容易,这个我就不说明了。大家一看就知道
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- datalist 分页的用户控件,我公司sunYun原创,如需转载,请联系作者
- 基于gridview的三层结构的代码演示 (一) 三层架构的实例演示(原创 如需转载请联系作者)
- 基于gridview的三层结构的代码演示 (二 ) 三层架构的实例演示 (原创,如需转载请联系作者)
- JAVA调用DLL的两种方法(作者不详,如有冒犯请速联系我,我只是用来参考)
- JAVA调用DLL的两种方法-ZPL中文打印(作者不详,如有冒犯,请联系我)
- 关于DataList控件也玩分页的我的修改
- struts2 文件上传与下载原理 (转载 如有侵权 请联系我 删除)
- DataList控件的分页代码
- 实现DataList控件的分页
- 实现DataList控件的分页
- linux下的存储管理----原创 转载请通知我!!!
- 关于C中的部分小知识点(都是转载,个人学习,如有侵权,请联系我删除~谢谢!)
- 兑现原创奖励,请超过5个竹币的朋友和我QQ联系
- 树状数据库设计方案思考(原创,如需转载请标明出处)
- DataList分页(转载)
- Repeater(DataList)控件的分页方法
- 定制自己的datalist分页控件
- 实现 DataList 或 Repeater 控件的分页
- 一个简单的自动发送邮件系统(一)
- 几个.net的重要问题
- 用PHP制作静态网站的模板框架(三)
- C#算法-----(一)选择排序
- 用PHP制作静态网站的模板框架(四)
- datalist 分页的用户控件,我公司sunYun原创,如需转载,请联系作者
- 用PHP制作静态网站的模板框架(二)
- Creating Custom Portal Modules
- 用PHP制作静态网站的模板框架(一)
- Server.Transfer,Response.Redirect 和 Page.Navigate
- 用Php实现链结人气统计
- 如何在.NET中实现事务(2)
- 写一个用户在线显示的程序
- Creating Collection Classes in C#