在移动开发教程中的案例代码,如何修改代码可以实现分页显示已经加载到datatable中的数据呢,同时每行首有序号列?2、自定义函数list的代码改为:
Dim e As RequestEventArgs = args(0)
'获取要显示的页
Dim page As Integer = 0 '默认page为0,显示第一页
Dim pageRows As Integer = 10 '每页10行
If e.GetValues.ContainsKey("page") Then '如果地址中有page参数
Integer.TryParse(e.GetValues("page"), page) '提取page参数
End If
Dim StartRow As Integer = page * pageRows + 1 '此页第一行
Dim EndRow As Integer = (page + 1) * pageRows '此页最后一行
'获取该页数据
Dim cmd As New SQLCommand
cmd.ConnectionName = "orders" '记得设置数据源名称
cmd.CommandText = "S elect Count(*) From {订单}"
Dim Count As Integer = cmd.ExecuteScalar() '获取总的行数
Dim Pages As Integer = Math.Ceiling(Count/PageRows) '计算出总页数
cmd.CommandText = "S elect * F rom (S elect Row_Number() Over(Order by 日期 desc) As [NO.],[_Identify],产品,客户,数量,单价,日期 From 订单) As a "
cmd.CommandText = cmd.CommandText & " Where [NO.]>= " & StartRow & " And [NO.] <= " & EndRow
Dim dt As DataTable = cmd.ExecuteReader
Dim wb As New WeUI
'根据此页数据生成网页
With wb.AddTable("","Table1")
.PageNumber = page '设置页码
.Primarykey = "_Identify" '设置主键
.CreateFromDataTable(dt)
End With
With wb.AddButtonGroup("","btg1", False) '生成换页按钮
If page > 0 Then
.Add("btnFirst", "首页","","List.htm?page=0")
.Add("btnPrev", "上一页","","List.htm?page=" & page - 1)
Else
.Add("btnFirst", "首页").Kind = 1
.Add("btnPrev", "上一页").Kind = 1
End If
If Endrow < count Then
.Add("btnNext", "下一页","","List.htm?page=" & page + 1)
.Add("btnLast", "末页","","List.htm?page=" & pages - 1)
Else
.Add("btnNext", "下一页").Kind = 1
.Add("btnNext", "末页").Kind = 1
End If
End With
With wb.AddButtonGroup("","btg2", False) '生成操作按钮
.Add("btnAdd", "增加订单").Attribute = ""
.Add("btnEdit", "编辑订单").Attribute = ""
.Add("btnDelete", "删除订单").Attribute = ""
End With
wb.AppendHTML("<script src='./lib/table.js'></script>") '引入脚本文件
e.WriteString(wb.Build)