DataList如何分页?

jadid 2003-07-28 05:50:43
我利用DataList显示图片,现在图片能正常显示了。不过怎么分页呢?
我可不想把所有图片显示在一页当中。太丑

哪位兄弟能指点指点?最好给点代码看看
...全文
50 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
carrel 2003-08-12
  • 打赏
  • 举报
回复
gz
pagefan 2003-07-28
  • 打赏
  • 举报
回复
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.SelectedIndex = -1;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
DataGrid1.DataBind();

}
xrll 2003-07-28
  • 打赏
  • 举报
回复
http://www.dotnetjunkies.com/Tutorial/ShowContent.aspx?cg=70E24E50-C179-4563-B053-2742516BF05B&ForumID=4039
xrll 2003-07-28
  • 打赏
  • 举报
回复
http://www.mastercsharp.com/article.aspx?articleid=76&&topicid=2
孟子E章 2003-07-28
  • 打赏
  • 举报
回复
c#
http://www.xiasp.com/school/aspnet/2002,15,151834.htm
孟子E章 2003-07-28
  • 打赏
  • 举报
回复
DATALIST分页的实例(VB.NET)


<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">
Dim connstr as String ="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&server.mappath("db\upload.mdb")&" "
Dim myconn As OleDbConnection = New OleDbConnection(connstr)
Dim Pagesize,Pagecount,RecordNum,CurrentPage as integer

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

'每页显示的个数
Pagesize=30
'联接数据库
myconn.open()


'计算总共有多少记录
Dim MyComm as OleDbCommand = new OleDbCommand("select count(*) as ID from data",myconn)
Dim dr as OleDbDataReader = MyComm.ExecuteReader()
Dim intCount as integer
if dr.Read() then
intCount =dr("ID")
else
intCount = 0
end if
dr.Close()
myconn.close()

lblRecordCount.Text =intcount
RecordNum=intcount
'计算总共有多少页

if recordnum mod pagesize=0 then
PageCount = RecordNum\PageSize
else
PageCount = RecordNum\PageSize +1
end if
' response.write(pagecount)
ViewState("PageCount") = PageCount

If Not IsPostBack then
CurrentPage = 0
ViewState("PageIndex") = 0
ListBind()
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
ListBind()

end sub


sub listbind()
Dim StartIndex as integer

StartIndex = CurrentPage*PageSize
Dim strSel as string = "select * from data"
Dim ds as DataSet = new DataSet()
Dim MyAdapter as OleDbDataAdapter = new OleDbDataAdapter(strSel,myconn)
MyAdapter.Fill(ds,StartIndex,PageSize,"Result")

DataList1.DataSource = ds.Tables("result").DefaultView
DataList1.RepeatDirection = RepeatDirection.Horizontal
DataList1.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>
<html>
<table border=0 width="100%" cellspacing=0 cellpadding=0 align="center" style=Font-Size:9pt>
<tr>
<td width="50%">
<div align="left">共有照片<asp:Label id="lblRecordCount" runat="server" />张</div>
</td>
<td width="50%">
<div align="right"><a href="upload.aspx" target="_blank">上传照片</a></div>
</td>
</tr>
</table>
<asp:DataList id="DataList1" runat="server"
width="100%"
align="center"
BorderColor="black"
CellPadding="3"
Font-Size="9pt"
RepeatColumns=6
Border=1
>
<ItemStyle HorizontalAlign="Center" width="16%" ></ItemStyle>
<ItemTemplate>
<a href="detail.aspx?&id=<%# DataBinder.Eval(Container.DataItem, "ID") %>" target="_blank">
<img border="0" src="viewpic.aspx?type=small&id=<%# DataBinder.Eval(Container.DataItem, "ID") %>" alt="编号:<%# DataBinder.Eval(Container.DataItem, "ID") %>
介绍:<%# DataBinder.Eval(Container.DataItem, "PicComment")%>
长度:<%# DataBinder.Eval(Container.DataItem, "picsize")%>K
时间:<%# DataBinder.Eval(Container.DataItem, "uploadtime")%>
分辨率:<%# DataBinder.Eval(Container.DataItem, "picrev")%>
点击数:<%# DataBinder.Eval(Container.DataItem, "ClickNum")%>
点击查看原图">
</a>
<br>
<font color=#808080>- <%# DataBinder.Eval(Container.DataItem, "ID") %> -</font>
<br>
<%# DataBinder.Eval(Container.DataItem, "PicComment") %>
<br>
<%# DataBinder.Eval(Container.DataItem, "Picsize") %>K

</ItemTemplate>
</ASP:Datalist>


<form runat=server >
<table width="100%" border="0" align="center" style=Font-Size:9pt>
<tr>

<td align=center>
<asp:LinkButton id="lbnPrevPage" Text="上一页" CommandName="prev" OnCommand="Page_OnClick" runat="server" />
<asp:LinkButton id="lbnNextPage" Text="下一页" CommandName="next" OnCommand="Page_OnClick" runat="server" />
</td>
</tr>
</table>
</form>

</html>

发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-28 05:50
社区公告

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

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