datalist vb.net分页技术

mmiiaaoo 2003-08-22 02:40:42
各位大虾:
是否能给小子一个datalist的分页实例,先谢谢各位!
...全文
37 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
spiketang 2003-08-23
  • 打赏
  • 举报
回复
自己看看,会有帮助的!
spiketang 2003-08-23
  • 打赏
  • 举报
回复
<%@ 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><<</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefPrevious"
onserverclick="ShowPrevious" runat="server">
<b><</b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefNext" onserverclick="ShowNext" runat="server">
<b>></b></a>
</td>
<td width="6%">
<a href="datalistpaging.aspx#this" ID="hrefLast" onserverclick="ShowLast" runat="server">
<b>>></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>

songwin 2003-08-22
  • 打赏
  • 举报
回复

<table width="620" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#003399">
<tr>
<td align="center" background="images/bg11.gif" bgcolor="#FFFFFF">
<asp:datalist ID="dlstproduce" RepeatColumns="2" RepeatDirection="Horizontal"
runat="server" ShowHeader="false"
Width="20">
<itemtemplate>
<table width="229" height="58" border="0" align="left" cellpadding="0" cellspacing="3">
<tr>
<td width="70" rowspan="3"> <a href='<%# String.Format("produceDetail.aspx?id={0}",Container.DataItem("pid")) %>' >
<img src='produceImages/<%# Container.DataItem("pimage")%>' height="80" width="50" border="1"></a></td>
<td width="64" class="spacetext">品 牌:</td>
<td width="83" align="left" class="spacetext"><div align="left">
<font color="#003366">
<%# Container.DataItem( "Ptype" ) %>
</font></div></td>
</tr>
<tr>
<td class="spacetext">型 号:</td>
<td class="spacetext"><div align="left"> <font color="#003366">
<%# Container.DataItem( "Pmodel" ) %>
</font></div></td>
</tr>
<tr>
<td class="spacetext">上市日期:</td>
<td><div align="left"></div></td>
</tr>
</table>
</itemtemplate>
</asp:datalist> </td>
</tr>
</table>
<SPAN style="LETTER-SPACING: 2px">
<table width="515" height="22" border="0" align="center" cellpadding="0" cellspacing="0" style=Font-Size:9pt>
<tr>
<td width="457" height="18" align=left> 产品共<%=RecordNum%> 件
<asp:linkbutton ID="lbnPrevPage" Text="上一页" CommandName="prev" OnCommand="Page_OnClick" runat="server" /> <asp:linkbutton ID="lbnNextPage" Text="下一页" CommandName="next" OnCommand="Page_OnClick" runat="server" />
共<%=pagecount%>页 当前第<%=CurrentPage+1%>页 转跳到第
<asp:textbox ID="txtgopage" Columns="2" runat="server"/>

<asp:button ID="btngopage" OnClick="Btngopage_click" CssClass="stext" Text="GOTO" runat="server"/>
</td>
</tr>
</table>
songwin 2003-08-22
  • 打赏
  • 举报
回复
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ import Namespace="system.data" %>
<script language="vb" runat="server">


'声明全局变量

Dim Pagesize,Pagecount,RecordNum,CurrentPage as integer
dim userid as string
dim strtype as string

Sub Page_Load(sender As System.Object, e As System.EventArgs)

dim strconstring as string
dim strconstring2 as string
dim strconstring3 as string
dim conquanliwen as oledbconnection
dim strtype as string
strconstring = ConfigurationSettings.AppSettings("connectionString")
strconstring2 = Server.MapPath(ConfigurationSettings.AppSettings("connectionString2"))
strconstring3 = strconstring & strconstring2

conquanliwen = new oledbconnection (strconstring3)

conquanliwen.open()
'BindDroplList
Dim cmdSelect As oledbCommand
Dim dtrtype As oledbDataReader
Dim cmdSelect2 As oledbCommand
Dim dtrtype2 As oledbDataReader
cmdSelect = New oledbCommand( "Select * From Producetype", conquanliwen)
dtrtype = cmdSelect.ExecuteReader()

droptype.DataSource = dtrtype
droptype.DataTextField = "Ttype"
droptype.DataBind()

dtrtype.Close()

cmdSelect2 = New oledbCommand( "Select * From Producetype", conquanliwen)
dtrtype2 = cmdSelect2.ExecuteReader()
dlsttype.DataSource = dtrtype2
dlsttype.DataBind()
dtrtype2.Close()
Pagesize=10
'联接数据库


Dim cmdcount as oledbCommand = new oledbCommand("select count(*) as nID from ProduceIntro",conquanliwen)
Dim dtrcount as oledbDataReader = cmdcount.ExecuteReader()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
if dtrcount.Read() then
RecordNum =dtrcount("nID")
else
RecordNum = 0
end if
dtrcount.Close()
conquanliwen.close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'计算总共有多少页
if Recordnum mod pagesize=0 then
PageCount = RecordNum\PageSize
else
PageCount = RecordNum\PageSize +1
end if

ViewState("PageCount") = PageCount

If Not IsPostBack then
CurrentPage = 0
ViewState("PageIndex") = 0
BindDataList
end if

End Sub



Sub Page_OnClick(sender As Object, e As CommandEventArgs)
CurrentPage = ViewState("PageIndex")
PageCount = ViewState("PageCount")

Dim cmd as string = e.CommandName
select case cmd
case "next":
if CurrentPage<(PageCount-1) then CurrentPage+=1
case "prev":
if CurrentPage>0 then CurrentPage-=1
end select
ViewState("PageIndex") = CurrentPage
BindDataList
End Sub

Sub btngoPage_Click(sender As Object, e As EventArgs)
CurrentPage = ViewState("PageIndex")
PageCount = ViewState("PageCount")
If txtgopage.text = "" then
CurrentPage = ViewState("PageIndex")
Else
CurrentPage = txtgopage.text - 1
If CurrentPage > PageCount - 1 then
CurrentPage = PageCount - 1
Else
CurrentPage = txtgopage.text - 1
End If
End If

ViewState("PageIndex") = CurrentPage
BindDataList
End Sub

Sub BindDataList
dim strconstring as string
dim strconstring2 as string
dim strconstring3 as string
dim conquanliwen as oledbconnection
dim strtype as string
strconstring = ConfigurationSettings.AppSettings("connectionString")
strconstring2 = Server.MapPath(ConfigurationSettings.AppSettings("connectionString2"))
strconstring3 = strconstring & strconstring2
Dim StartIndex as integer

conquanliwen = new oledbconnection (strconstring3)

StartIndex = CurrentPage*PageSize
Dim strSelect as string = "select * from ProduceIntro"
Dim dst as DataSet = new DataSet()
Dim Dadproduce as oledbDataAdapter = new oledbDataAdapter(strSelect,conquanliwen)
Dadproduce.Fill(dst,StartIndex,PageSize,"ProduceIntro")

dlstproduce.DataSource = dst.Tables("ProduceIntro").DefaultView
dlstproduce.RepeatDirection = RepeatDirection.vertical
dlstproduce.DataBind()

lbnNextPage.Enabled = true
lbnPrevPage.Enabled = true
if(CurrentPage=(PageCount-1)) then lbnNextPage.Enabled = false
if(CurrentPage=0) then lbnPrevPage.Enabled = false

end sub

</script>
sizheng0320 2003-08-22
  • 打赏
  • 举报
回复
up

62,041

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧