关于GridView排序的问题,大家帮帮忙呀!!!
我的GridView需要手动绑定排序,其中有一列是计算哪些列是否为空,我在OnRowDataBound中对每一行的所有列判断是否为空,然后把统计的数字写入统计缺项的列,但是当排序的时候,别的列可以SortExpression= "字段名 ",这个统计缺项的列如何进行排序呢?
不知道我说清楚没有,希望大家帮帮忙呀!!!
------解决方案--------------------不太明白,可否举个例子,说具体一点..
------解决方案--------------------象这种有统计列,最好还是在SQL语句或者存储过程那里处理,没有必要在前台处理.
------解决方案--------------------手动绑定排序?自己在sql里面排序就可以啊
------解决方案--------------------using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TedaBus.RFPrincipal;
/// <summary>
/// 行政用车申请列表页面
/// 创建:叶明
/// 创建日期:2007-03-09
/// 修改记录:
/// </summary>
public partial class OfficeUseBus_ApplyUseBusList : SimpleCode
{
DataSet ds = new DataSet( "BusUseRecord "); //存储申请记录的数据集
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindUseBusRecordList();
}
}
protected void btnShowFilter_Click(object sender, EventArgs e)
{
//设置筛选Panel的可见性
pnlFilter.Visible = !pnlFilter.Visible;
}
/// <summary>
/// 绑定行政用车记录GridView
/// 涉及数据表:OfficeUseBusRecord
/// </summary>
private void BindUseBusRecordList()
{
string sql = "SELECT * FROM OfficeUseBusRecord WHERE valid = 1 AND DeptID = " + GetCurrentUserDeptID();
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[ "TedabusMIS "].ToString());
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
sda.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
//对于数据视图的RowFilter选项,我先将其赋值为一个总是为真的条件,然后根据用户的选择逐步增加其限制
string filterString = "1 = 1 ";
//处理开始查询的日期
if (ViewState[ "StartDate "] != null)
{
if (ViewState[ "StartDate "].ToString() != string.Empty)
{
filterString += " and UserBusDate > # " + ViewState[ "StartDate "].ToString() + "# ";
}
}
//处理最晚查询的日期
if (ViewState[ "EndDate "] != null)
{
if (ViewState[ "EndDate "].ToString() != string.Empty)
{
filterString += " and UserBusDate < # " + ViewState[ "EndDate "].ToString() + "# ";
}
}
dv.RowFilter = filterString;
//处理GridView的排序
if (ViewState[ "sort "] != null)
{
if(ViewState[ "sort "].ToString() != string.Empty)
{
dv.Sort = ViewState[ "sort "].ToString();
}
else
{
dv.Sort = " ";
}
}
gvUseBusRecord.DataSource = dv;
gvUseBusRecord.DataBind();