2.下面这个方法是自己写的,翻页事件中调用。
private void ChangePageDataBind()
{
DataView dv = 得到数据代码;
string strSort = "";
string strOrder ="";//排序方式。0,降序,1升序
if(ViewState["SortExpresstion"] != null)
{
strSort = ViewState["SortExpresstion"].ToString();
strSort = strSort.Substring(0,strSort.Length -1);
strOrder = ViewState["SortExpresstion"].ToString();
strOrder = strOrder.Substring(strOrder.Length -1);
}
if(this.ViewState["SortExpresstion"] != null)
{
if(strSort == "CustomerName")
{
if(strOrder == "1")
{
this.ViewState["SortExpresstion"] = "CustomerName1";
dv.Sort = "CustomerName ASC";
}
else
{
this.ViewState["SortExpresstion"] = "CustomerName0";
dv.Sort = "CustomerName DESC";
}
}
}
if(this.ViewState["SortExpresstion"] != null)
{
if(strSort == "fullName")
{
if(strOrder == "1")
{
this.ViewState["SortExpresstion"] = "fullName1";
dv.Sort = "fullName ASC";
}
else
{
this.ViewState["SortExpresstion"] = "fullName0";
dv.Sort = "fullName DESC";
}
}
}
this.grdProjTrace.DataSource = dv;
this.grdProjTrace.DataBind();
}
上面两方法只要修改要排序的字段名,就可以直接调用了.
