分页代码
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
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
2.直接在GRIDVIEW里的重绘事件里写,更方便
int i=0;
var templist= from a in db.CWName
select xxMOdel
{
index=i++,
field1=a.field1,
field2=a.field2, ..........
}
/// 分页
/// </summary>
/// <param name="Count">总条数</param>
/// <param name="page">当前页</param>
/// <param name="pageSize">每页显示的记录总数</param>
/// <returns></returns>
public PageGridView GetPageGridView(int Count, int page = 1, string type = "defalut", int pageSize = 20)
{
int index=1;
var MyGridView = new PageGridView
{
index++;//这样对吗?版主
CurrentPageIndex = page,
PageSize = pageSize,
TotalRecordCount = Count,
Type = type
};
return MyGridView;
}
是在这个分页里面定义吗?