首页 新闻 会员 周边 捐助

razor WebGrid 序号怎么做?

0
[已解决问题] 解决于 2017-05-17 21:19
复制代码
@{
    var db = Database.Open("rcdb");
    var selectCommand = "SELECT * FROM Users";
    var searchTerm = "";

    if (!Request.QueryString["searchTitle"].IsEmpty())
    {
        selectCommand = "SELECT  * FROM Users WHERE UserName LIKE @0";
        searchTerm = "%" + Request["searchTitle"] + "%";
    }

    var selectedData = db.Query(selectCommand, searchTerm);
    var grid = new WebGrid(source: selectedData, rowsPerPage: 20);
}

//body部分
<div class="content01" id="content01">
    <form name="listForm"  method="post" id="listForm">
    <div>
    @grid.Table(
                tableStyle: "grid",
                headerStyle: "gridhead",
                footerStyle: "gridfooter",
                alternatingRowStyle: "alt",
                columns: grid.Columns(
                grid.Column("", format:@<input type="checkbox" class="cb" name="id" value="@item.Id">, canSort: false),
                grid.Column("Id", "Id"),
                grid.Column("UserName", "账号"),
                grid.Column("Email", "邮箱"),
                grid.Column("Role", "角色",format:@<span>@if(item.Role == 0){<text>普通会员</text>}else{ <text>超级会员</text>}</span>),
                grid.Column("OrderNum", "排序"),
                grid.Column("Status", "状态",format:@<span>@if(item.Status == 0){<text>开启</text>}else{ <text>关闭</text>}</span>),
                grid.Column("操作",format: @<a href="userEdit?id=@item.Id">设置</a>),
                grid.Column("操作",format: @<a href="userDelete?id=@item.Id">删除</a>)
                                    )
                                )
  </div>
  <div>
    <div class="pageleft">
      <input type="checkbox" name="chkbtn" value="" onclick="checkAll(this)">&nbsp;
      <input type="submit" class="button03" name="btn" id="btn0201" value="设置状态"/>
      <input type="submit" class="button03" name="btn" id="btn0202" value="删除"/>
    </div>
    <div class="page">
    @grid.Pager(
                mode: WebGridPagerModes.All,
                firstText: "首页",
                previousText: "上一页",
                nextText: "下一页",
                lastText: "末页",
                numericLinksCount: 5
             )
    </div>
  </div>
  </form>
</div>
复制代码
缘分0919的主页 缘分0919 | 初学一级 | 园豆:96
提问于:2016-10-20 12:09
< >
分享
最佳答案
0

用jquery比较简单

//给表格添加序号
$(function () {
$('.sn').each(function (index) {
sn= index+1;
$(this).append(sn);
});
});

缘分0919 | 初学一级 |园豆:96 | 2017-05-17 21:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册