手工编码传递主键

如果因为特殊原因,不能采用CreateFromDataTable或CreateFromTable自动生成表格,那就需要逐行设置Primarykey属性了 ,例如:

Dim wb As New WeUI
With
wb.AddTable("","Table1")
    Dim nms() As String = {"
产品","客户","数量","单价","日期"}
    .Head.AddRow(nms)
    For Each r As DataRow In DataTables("
订单").DataRows
        With .Body.AddRow(r("
产品"),r("客户"),r("数量"))
            .Primarykey = r("_Identify") '
设置主键
            .AddCell(Format(r("
单价"),"#0.00"))
            .AddCell(Format(r("
日期"),"MMdd"))
       
End With
    Next

End
With

上述代码假定订单表的主键列是"_Identity",表格每增加一行,就将其Primarykey属性设置为对应DataRow的"_Identify"列的值。

完整示例

HttpRequest事件代码:

Select Case e.Path
    Case "list.htm"
        '获取要显示的页
        Dim page As Integer = 0 '默认page为0,显示第一页
        Dim pageRows As Integer = 15 '每页15行
        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 = "Select Count(*) From {订单}"
        Dim Count As Integer = cmd.ExecuteScalar() '获取总的行数
        cmd.CommandText = "Select * From (Select Row_Number() Over(Order by 日期) 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.AddActionSheet("","menu") '设计菜单
            .Add("mnudAdd", "增加订单").Attribute="onclick=""alert('增加订单')"""
            .Add("mnuEdit", "编辑订单").Attribute ="onclick=""alert('编辑订单页码:'+table1.pagenumber+ '主键:'+ table1.primarykey)"""
            .Add("mnuDelete", "删除订单").Attribute ="onclick=""alert('删除订单页码:'+table1.pagenumber+ '主键:'+ table1.primarykey)"""
            .Add("mnuCancel","取消","",True)
        End With
        '根据此页数据生成网页
        With wb.AddTable("","Table1")
            .PageNumber = page '设置页码
            .ActiveSheet = "menu"
             Dim nms() As String = {"NO.","产品","客户","数量","单价",
"日期"}

          
  .Head.AddRow(nms)
             For Each r As DataRow In dt.DataRows
               
With .Body.AddRow(r("NO."),r("产品"),r("客户"),r("数量"))
                    .Primarykey = r("_Identify")
'设置主键
                    .AddCell(Format(r("单价"),"#0.00"))
                    .AddCell(Format(r("日期"),"MM月dd日"))
                End With
            Next
        End With
        With wb.AddButtonGroup("","btg2", False)
            If page > 0 Then
                .Add("btnPrev", "上一页","","List.htm?page=" & page - 1)
            End If
            If Endrow < count Then
                .Add("btnNext", "下一页","","List.htm?page=" & page + 1)
            End If
        End With
        e.WriteString(wb.Build)

End
Select

同样Select语句必须将主键列包括进来。

现在你在客户端浏览器连续点击某行,会出现菜单,在点击菜单中的命令,会显示当前页码和当前行的主键。

下图是我在iPhone按着上述操作后截图:

 


本页地址:http://www.foxtable.com/mobilehelp/topics/0119.htm