首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

.net mvc 三 分页,显示数据序号自增?

2013-08-16 
.net mvc 3 分页,显示数据序号自增????分页代码IListUserSexCode uList userSexCodeService.GetModelL

.net mvc 3 分页,显示数据序号自增????

分页代码
            IList<UserSexCode> uList = userSexCodeService.GetModelList("");
          //  ViewBag.Ulist = uList;
            if (String.IsNullOrEmpty(page))
            {
                page = "1";
            }

            var model = GetPageGridView(uList.Count, Convert.ToInt32(page));
            ViewBag.MyGridView = model;
            ViewBag.Ulist = uList
                .OrderByDescending(x => x.serialnumber)
               .Skip((model.CurrentPageIndex - 1) * model.PageSize)
               .Take(model.PageSize)
               .ToList();

      显示代码
@{
    Layout = "~/Views/Shared/_Blank.cshtml";
    int index = 1;
}
<link href="@Url.Content("~/Styles/bootstrap.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Styles/theme.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Styles/bootstrap-responsive.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery.min.js")"></script>
<script src="@Url.Content("~/Scripts/bootstrap.js")"></script>
<script src="@Url.Content("~/Scripts/superfish.js")"></script>
<table cellspacing="0" class="table table-condensed table-striped" id="mytable">
       <thead>
        <tr>
            <th>编号</th>
            <th>代码</th>
            <th>名称</th>
            <th>简称</th>


            <th>级数</th>
            <th>是否有效</th>
            <th>排序编号</th>
        </tr>
       </thead>
       <tbody>
   @foreach (Vamdow.TSWSolution.Model.ChinaAndWorldNameCode item in ViewBag.CWName)
   {
    <tr>
            <td>@index</td>
            <td>@item.code</td>
            <td>@item.codename</td>
            <td>@item.codeshortname</td>
            <td>@item.codelevel</td>
               @if (item.valid == 0)
            {
            <td>否</td>
            }
            else { 
            <td>是</td>
            }
            <td>@item.serialnumber</td>
       </tr>
       
       index++;
      
   }
  
   </tbody>
</table>
 
 @Html.Partial("~/Views/MyGridView/_Pager.cshtml", ViewBag.MyGridView as Vamdow.TSWSolution.Web.Models.Utility.PageGridView)

<script type="text/javascript">
    var currentPage = 1;
    //分页
    function GetMyGridView(CurrentPageIndex, type) {
        currentPage = CurrentPageIndex; // 保存当前页码
        
        switch (type) {
            case "Search":


                Query(CurrentPageIndex);
                break;
            default:
                location.href = "/OrganizeStandards/ChinaAndWorldNameCodeList?page=" + CurrentPageIndex;

        }
    }
  
</script>


没有id,序号,自己在页面定义的index=1,循环index++作为序号,但是当点击第二页的时候,又重index=1开始了,如何让index序号一直循环下去,求解 分页 MVC
[解决办法]
1.用当前页数索引和每页大小来算。比如一共10也,每页显示10条,那你查看第一条就是1-10,第二条就要另外算,[(当前第几页-1)*10,(当前第几页-1)*10+10]
2.直接在GRIDVIEW里的重绘事件里写,更方便
[解决办法]
你可以在ViewBag.CWName数据源里面添加自增序号

using(var db=DBDataContent())
int  i=0;
var templist= from a in db.CWName
select xxMOdel
{
  index=i++,
  field1=a.field1,
  field2=a.field2,

  ..........
}

热点排行