数据集排序and表头点击排序

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StaticsicsVehicle.aspx.cs"
Inherits="GECMP.Statistics.StaticsicsVehicle" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="pagerForm" method="post" action="Statistics/StaticsicsVehicle.aspx">
<input type="hidden" name="status" value="status">
<input type="hidden" name="keywords" value="keywords" />
<input type="hidden" name="pageNum" value="1" />
<input type="hidden" name="numPerPage" value="<%=NumPerPage%>" />
<input type="hidden" name="orderField" value="<%= Request["orderField"]%>" />
<input type="hidden" name="orderDirection" value="<%=Request["orderDirection"]%>" />
<input type="hidden" name="Title" value="add" />
</form>
<div class="pageContent">
<div id="jbsxBox" class="unitBox" style="margin-left: 0px; margin-top: 2px;">
<div class="pageHeader">
<!--<搜索栏>-->
<form οnsubmit="return navTabSearch(this);" action="Statistics/StaticsicsVehicle.aspx"
method="post" rel="pagerForm">
<div class="searchBar">
<table class="searchContent">
<tr>
<td><p>
<label>
开始时间:</label>
<input type="text" name="startDate" class="date" datefmt="yyyy-MM-dd HH:mm:ss"
value="<%=Request["startDate"] %>" />
</td>
<td>
<label>
结束时间:</label>
<input type="text" name="overDate" class="date" datefmt="yyyy-MM-dd HH:mm:ss" value="<%=Request["overDate"] %>"
mindate="1955-01-01" maxdate="2020-12-31" />

</td>
<td>
<div class="subBar">
<ul>
<li>
<input type="submit" name="btnSearch" value="检索" /></li>
</ul>
</div>
</td>
</tr>
</table>
</div>
</form>
<!--</搜索栏selectedTodo>-->
</div>
<div class="pageContent">
<div class="panelBar">
<ul class="toolBar">
<li> <a class="icon" href="../Statistics/StaticsicsVehicleToExcel.aspx?start=<%=startDate %>&end=<%=overDate %>" target="dwzExport"
targettype="navTab" title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li>
</ul>
</div>
<table class="table" width="100%" layouth="110">
<thead>
<tr>
<%-- <th width="2%" style="text-align: left;">
<input type="checkbox" group="ids" class="checkboxCtrl">
</th>--%>
<th width="10%" style="text-align: left;">
牌照号码
</th>
<th width="10%" style="text-align: left;">
现驾驶员
</th>
<th width="10%" style="text-align: left;" orderField="TotalDays" class="<%=Request["orderDirection"] %>">
长途出车天数
</th>
<th width="10%" style="text-align: left;" orderField="TotalNum" class="<%=Request["orderDirection"] %>">
长途出车次数
</th>
<th width="10%" style="text-align: left;" orderField="TotalInNum" class="<%=Request["orderDirection"] %>">
市内出车次数
</th>
</tr>
</thead>
<tbody>
<asp:Repeater ID="repeaterDriver" runat="server">
<ItemTemplate>
<tr target="id" rel="<%#Eval("VehicleID") %>">
<%-- <td>
<input name="ids" type="checkbox" value='<%# DataBinder.Eval(Container.DataItem, "VehicleID")%>'>
</td>--%>
<td>
<%#DataBinder.Eval(Container.DataItem, "VehicleNo")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "TotalDays")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "TotalNum")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "TotalInNum")%>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</tbody>
</table>
<div class="panelBar">
<div class="pages">
<span>显示</span>
<select class="combox" name="numPerPage" οnchange="navTabPageBreak({numPerPage:this.value})">
<option value="<%=NumPerPage%>">选择</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<span>条,共
<%=TotalCount%>
条</span>
</div>
<div class="pagination" targettype="navTab" totalcount="<%=TotalCount%>" numperpage="<%=NumPerPage%>"
pagenumshown="<%=PageNumShown%>" currentpage="<%=PageNum%>">
</div>
</div>
</div>
</div>
</div>
</body>
</html>

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GECMP_IDAL;
using System.Data;

namespace GECMP.Statistics
{
public partial class StaticsicsVehicle : System.Web.UI.Page
{

#region 字段
private int numPerPage;
private int pageNumShown = 10;
private int pageNum;
private int totalCount;
public string cid;
public string startDate = "";
public string overDate = "";

DBOperator dbo = DBOperatorFactory.GetDBOperator();
#endregion

#region 属性
/// <summary>
/// 每页显示的条数
/// </summary>
public int NumPerPage
{
get
{
int temp = Convert.ToInt32(Request.Form["numPerPage"]);
return temp == 0 ? 20 : temp;
}
set { numPerPage = value; }
}

/// <summary>
/// 页数导航的个数
/// </summary>
public int PageNumShown
{
get { return pageNumShown; }
set { pageNumShown = value; }
}

/// <summary>
/// 当前显示的页数
/// </summary>
public int PageNum
{
get
{
int temp = Convert.ToInt32(Request.Form["pageNum"]);
return temp == 0 ? 1 : temp;
}
set { pageNum = value; }
}

/// <summary>
/// 总条数
/// </summary>
public int TotalCount
{
get { return totalCount; }
set { totalCount = value; }
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
string str = Request.HttpMethod;
if (!IsPostBack)
{
DataToBind();
}
}
private void DataToBind()
{
string str = Request["orderField"];
string str1 = Request["orderDirection"];
DataSet ds;
DataTable dt;
startDate = Request["startDate"] == null ? string.Empty : Request["startDate"]; //车辆类型
overDate = Request["overDate"] == null ? string.Empty : Request["overDate"]; //现驾驶员
string userName = string.Empty;
//object[] para= new object[2];
//para[0] = GetDateTime(startDate);
//para[1] = GetDateTime(overDate);

object[] para = new object[2];
para[0] = GetDateTime(startDate);
para[1] = GetDateTime(overDate);
dt = dbo.ExecProcReDataTable("SP_StatisticsVehicle", para);
if (!string.IsNullOrEmpty(Request["orderField"]) && !string.IsNullOrEmpty(Request["orderDirection"]))
{
DataView dv = dt.AsDataView();
dv.Sort = Request["orderField"] + " " + Request["orderDirection"];
dt = dv.ToTable();

}
TotalCount = dt.AsEnumerable().Count();
if (TotalCount == 0)
{
repeaterDriver.DataSource = dt.DefaultView;
}
else
{
EnumerableRowCollection<DataRow> dr = dt.AsEnumerable().Where(item => item["Name"].ToString().Contains(userName));
dt = dr.Count() == 0 ? null : dr.CopyToDataTable<DataRow>();
if (dt != null)
{
TotalCount = dt.Rows.Count;

dt = dt.AsEnumerable().Skip((PageNum - 1) * NumPerPage).Take(NumPerPage).CopyToDataTable<DataRow>();
}
else { TotalCount = 0; }
repeaterDriver.DataSource = dt;
}

repeaterDriver.DataBind();
}
#region 时间方法

private object GetDateTime(string str)
{
if (string.IsNullOrEmpty(str))
{
return DBNull.Value;
}
else
{
return DateTime.Parse(str);
}
}
#endregion
}
}

转载于:https://www.cnblogs.com/sijiyong/p/3532164.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值