要想實現翻頁後繼續排序
比如共
則排序時:第一頁將前
要注意以下幾點:
示例如下:
private void grdProjTrace_SortCommand(object source DataGridSortCommandEventArgs e)
{
this grdProjTrace CurrentPageIndex = ;
DataView dv = 得到數據代碼;
string strSort = ;
string strOrder = ;//排序方式 降序 升序
if(ViewState[ SortExpresstion ] != null)
{
strSort = ViewState[ SortExpresstion ] ToString();
strSort = strSort Substring( strSort Length );
strOrder = ViewState[ SortExpresstion ] ToString();
strOrder = strOrder Substring(strOrder Length );
}
if(e SortExpression == CustomerName )
{
if(strSort != CustomerName )
{
this ViewState[ SortExpresstion ] = ustomerName ;
dv Sort = CustomerName DESC ;
}
else
{
if(strOrder == )
{
this ViewState[ SortExpresstion ] = CustomerName ;
dv Sort = CustomerName ASC ;
}
else
{
this ViewState[ SortExpresstion ] = CustomerName ;
dv Sort = CustomerName DESC ;
}
}
}
if(e SortExpression == fullName )
{
if(strSort != fullName )
{
this ViewState[ SortExpresstion ] = fullName ;
dv Sort = fullName DESC ;
}
else
{
if(strOrder == )
{
this ViewState[ SortExpresstion ] = fullName ;
dv Sort = fullName ASC ;
}
else
{
this ViewState[ SortExpresstion ] = fullName ;
dv Sort = fullName DESC ;
}
}
}
this grdProjTrace DataSource = dv;
this grdProjTrace DataBind();
}
> private void ChangePageDataBind()
{
DataView dv = 得到數據代碼;
string strSort = ;
string strOrder = ;//排序方式 降序 升序
if(ViewState[ SortExpresstion ] != null)
{
strSort = ViewState[ SortExpresstion ] ToString();
strSort = strSort Substring( strSort Length );
strOrder = ViewState[ SortExpresstion ] ToString();
strOrder = strOrder Substring(strOrder Length );
}
if(this ViewState[ SortExpresstion ] != null)
{
if(strSort == CustomerName )
{
if(strOrder == )
{
this ViewState[ SortExpresstion ] = CustomerName ;
dv Sort = CustomerName ASC ;
}
else
{
this ViewState[ SortExpresstion ] = CustomerName ;
dv Sort = CustomerName DESC ;
}
}
}
if(this ViewState[ SortExpresstion ] != null)
{
if(strSort == fullName )
{
if(strOrder == )
{
this ViewState[ SortExpresstion ] = fullName ;
dv Sort = fullName ASC ;
}
else
{
this ViewState[ SortExpresstion ] = fullName ;
dv Sort = fullName DESC ;
}
}
}
this grdProjTrace DataSource = dv;
this grdProjTrace DataBind();
}
上面兩方法只要修改要排序的字段名
private void grdProjTrace_PageIndexChanged(object source DataGridPageChangedEventArgs e)
{
try
{
try
{
this grdProjTrace CurrentPageIndex = e NewPageIndex;
}
catch
{
this grdProjTrace CurrentPageIndex = ;
}
this ChangePageDataBind();
}
catch(System Exception errWS)
{
//異常
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11882.html