我有一个简单的数据主义者。
<asp:DataList ID="MyDataList" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" cssClass="row">
<ItemTemplate>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 img-thumbnail" style="width:300px; height:450px; border: 1px solid black;">
<div class="text-center"><%# Eval("age")%></div>
<br/>
<div class="text-center"><%# Eval("name") %></div>
</div>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindGridData()
End If
End Sub
Protected Sub BindGridData()
Dim sqlConn1 As New OdbcConnection(myConnectionString1)
Dim dt As DataTable = New DataTable
Try
sqlConn1.Open()
Dim Query1 As String = "Select age, name from myTable "
Dim cmd1 = New OdbcCommand(Query1, sqlConn1)
Dim reader1 As OdbcDataReader = cmd1.ExecuteReader()
dt.Load(reader1)
Session("SaveData") = dt
MyDataList.DataSource = Session("SaveData")
MyDataList.DataBind()
reader1.Close()
sqlConn1.Close()
Catch ex As Exception
End Try
End Sub
我的问题如何进行DataList分页?例如,在我的DataList的末尾,我希望:(1) (2) (3) (4) (...)
类似于GridView
我已经在bindgriddata()
内的会话中保存了我的SQL查询。也许我可以用它?
我知道在GridView中它很简单,你只需执行以下操作即可,但我如何使用DataList执行此操作?
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
GridView1.PageIndex = e.NewPageIndex
GridView1.DataSource = Session("SaveData")
GridView1.DataBind()
End Sub