| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1205 人关注过本帖
标题:DataList分页
只看楼主 加入收藏
baoyue9
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-12-21
收藏
 问题点数:0 回复次数:1 
DataList分页

谁能给一个DataList分页的C#模块?

[此贴子已经被作者于2006-5-21 10:21:16编辑过]

搜索更多相关主题的帖子: DataList 模块 
2006-05-16 14:27
小笨笨
Rank: 5Rank: 5
等 级:贵宾
威 望:19
帖 子:1169
专家分:0
注 册:2006-4-17
收藏
得分:0 

以下是转的

由于DataList不支持内建的分页机制,因此,我们必须使用 SqlDataAdapter对象的Fill方法来实现分页,Fill方法主要用来增加或刷新DataSet的记录行。Fill方法已经被重载,我们这里选用四个参数的那个重载方法:DataSet, startRecord, maxRecords 和 TableName。

<%@ Import NameSpace="System.Data.OleDb" %>
<%@ Import NameSpace="System.Data" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not Page.IsPostBack() Then
intPageSize.Text = "2"
intCurrIndex.Text = "0"
DataBind()
End If
End Sub

Private Sub DataBind()
Dim CnString As String
CnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
CnString = CnString + Server.MapPath("dataDB.mdb"))
Dim objConn As New OleDbConnection(CnString)
Dim objDA As New OleDbDataAdapter("SELECT * FROM Document ORDER BY CreateDate DESC", objConn)
Dim objDS As New DataSet()

If Not Page.IsPostBack() Then
objDA.Fill(objDS)
intRecordCount.Text = CStr(objDS.Tables(0).Rows.Count)
objDS = Nothing
objDS = New DataSet()
End If

objDA.Fill (objDS, CInt(intCurrIndex.Text), CInt(intPageSize.Text), "Document")

dList.DataSource = objDS.Tables(0).DefaultView
dList.DataBind()
objConn.Close()
PrintStatus()
End Sub

Public Sub ShowFirst(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = "0"
DataBind()
End Sub


Public Sub ShowPrevious(ByVal s As Object, ByVal e As EventArgs)
intCurrIndex.Text = Cstr(Cint(intCurrIndex.Text) - CInt(intPageSize.Text))
If CInt(intCurrIndex.Text) < 0 Then
intCurrIndex.Text = "0"
End If
DataBind()
End Sub

Public Sub ShowNext(ByVal s As Object, ByVal e As EventArgs)
If CInt(intCurrIndex.Text) + 1 < CInt(intRecordCount.Text) Then
intCurrIndex.Text = CStr(CInt(intCurrIndex.Text) + CInt(intPageSize.Text))
End If
DataBind()
End Sub

Public Sub ShowLast(ByVal s As Object, ByVal e As EventArgs)
Dim tmpInt as Integer

tmpInt = CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)
If tmpInt > 0 Then
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - tmpInt)
Else
intCurrIndex.Text = Cstr(CInt(intRecordCount.Text) - CInt(intPageSize.Text))
End If
DataBind()
End Sub

Private Sub PrintStatus()
lblStatus.Text = "总记录数:<b>" & intRecordCount.Text
lblStatus.Text += "</b> 当前:<b> "
lblStatus.Text += CStr(CInt(CInt(intCurrIndex.Text) / CInt(intPageSize.Text)+1))
lblStatus.Text += "</b>/<b>"

If (CInt(intRecordCount.Text) Mod CInt(intPageSize.Text)) > 0 Then
lblStatus.Text += CStr(CInt(CInt(intRecordCount.Text) / CInt(intPageSize.Text)+1))
Else
lblStatus.Text += CStr(CInt(intRecordCount.Text) / CInt(intPageSize.Text))
End If
lblStatus.Text += "</b>"
End Sub
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<TABLE height="528" cellSpacing="0" cellPadding="0" width="244" border="0"
ms_2d_layout="TRUE">
<TBODY>
<TR vAlign="top">
<TD width="244" height="528">
<form id="Form1" method="post" runat="server">
<TABLE height="227" cellSpacing="0" cellPadding="0" width="516" border="0"
ms_2d_layout="TRUE">
<TR vAlign="top">
<TD width="10" height="15"></TD>
<TD width="506"></TD>
</TR>
<TR vAlign="top">
<TD height="48"></TD>
<TD>
<h2 align="center"><font face="verdana">Paging in DataList</font></h2>
</TD>
</TR>
<TR vAlign="top">
<TD height="106"></TD>
<TD>
<a name="this"></a>
</TD>
</TR>
<TR vAlign="top">
<TD height="19"></TD>
<TD rowSpan="2">
<table width="505" align="right" height="25">
<tr>
<td width="76%" align="left">
<asp:label ID="lblStatus" Runat="server" Font-Name="verdana" Font-Size="10pt" />
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefFirst" onserverclick="ShowFirst" runat="server">
<b>&lt;&lt;</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefPrevious"
onserverclick="ShowPrevious" runat="server">
<b>&lt;</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext" runat="server">
<b>&gt;</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefLast" onserverclick="ShowLast" runat="server">
<b>&gt;&gt;</b></a>
</td>
</tr>
</table>
</TD>
</TR>
<TR vAlign="top">
<TD height="19"></TD>
<TD>
<asp:label ID="intPageSize" Visible="False" Runat="server" /></TD>
</TR>
<TR vAlign="top">
<TD height="20"></TD>
<TD>
<asp:label ID="intRecordCount" Visible="False" Runat="server" /></TD>
</TR>
<asp:DataList ID="dList" Runat="server" Width="100%"
ItemStyle-BackColor="Beige" ItemStyle-Font-Name="宋体"
BorderWidth="1" HeaderStyle-Font-Name="Verdana" EnableViewState="False">
<HeaderTemplate>
<table width="100%" style="font: 10pt verdana" cellpadding="0" cellspacing="0">
<tr style="background-color:FF0000">
<th align="left">
<font color="#FFFFFF">Store ID</font></th>
<th align="left">
<font color="#FFFFFF">Order Number</font></th>
<th align="left">
<font color="#FFFFFF">Order Date</font></th>
<th align="left">
<font color="#FFFFFF">Qty</font></th>
<th align="left">
<font color="#FFFFFF">Title ID</font></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#f5f5dc">
<td><%# DataBinder.Eval(Container.DataItem, "id") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Title") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Author") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "Source") %></td>
<td><%# DataBinder.Eval(Container.DataItem, "CreateDate") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
</TABLE>
</FooterTemplate>
</asp:DataList>
<asp:label ID="intCurrIndex" Visible="False" Runat="server" />
</TABLE>
</FORM>
</TD></TR>
</TBODY>
</TABLE>
</body>
</HTML>


欢迎光临我的博客: http://smallfools.blog./default.html
2006-05-16 14:30
快速回复:DataList分页
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016159 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved