DataList 显示数据库图片问题
用Microsoft Visual Studio 2005环境中的VB做一个图片搜索系统在datalist控件放imagebutton控件
现在的问题是怎么把生成的图片分页显示?每一页只显示15个图片?现在的情况是把数据库中的图片都显示出来了。数据库中有58个图片。
我的代码
fpath:路径
fname:图片名
数据库:postcard_db
Protected Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fpath As String = String.Empty
Dim fname As String = String.Empty
Dim imgurl As String = String.Empty
Dim cn As New SqlConnection("Data Source=(local)\SQLEXPRESS;Initial Catalog=postcard_db;User ID=sa;Password=123456")
Dim sql As String = "SELECT fpath,fname FROM MAIN"
Dim cmd As New SqlCommand(sql, cn)
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
DataList.datasource =dr
DataList.DataBind()
dr.close()
Dim imageList As New ArrayList
Dim dr2 As SqlDataReader = cmd.ExecuteReader
While dr2.Read = True
fpath = dr2("fpath")
fname = dr2("fname")
imageList.Add(fpath & fname & ".jpg")
End While
dr2.Close()
cn.Close()
For i As Integer = 0 To imageList.Count - 1
"图片的显示代码
CType(DataList.Items(i).FindControl("ImageButton"), ImageButton).ImageUrl = imageList(i)
CType(DataList.Items(i).FindControl("ImageButton"), ImageButton).Width = 100
CType(DataList.Items(i).FindControl("ImageButton"), ImageButton).Height = 100
Next
End Sub --------------------编程问答-------------------- 0分
不好吧?
要分页两种选择:
第一,自己编写分页代码,然后编辑每个页显示的行(代码需要自己编写)
第二,下分页控件,设置每页显示的行(代码在控件里已编写好,不需要自己编写)
补充:.NET技术 , ASP.NET