手把手教你如何扩展GridView之自动排序篇
[1] 手把手教你如何扩展GridView之自动排序篇
[2] 手把手教你如何扩展GridView之自动排序篇
[3] 手把手教你如何扩展GridView之自动排序篇
[4] 手把手教你如何扩展GridView之自动排序篇
[2] 手把手教你如何扩展GridView之自动排序篇
[3] 手把手教你如何扩展GridView之自动排序篇
[4] 手把手教你如何扩展GridView之自动排序篇
和下面的属性
public string SortExpressionEx
{
get
{
if (ViewState["SortExpressionEx"] == null)
{
return null;
}
return ViewState["SortExpressionEx"].ToString();
}
set
{
ViewState["SortExpressionEx"] = value;
}
}
{
get
{
if (ViewState["SortExpressionEx"] == null)
{
return null;
}
return ViewState["SortExpressionEx"].ToString();
}
set
{
ViewState["SortExpressionEx"] = value;
}
}
然后重写OnSorting事件如下:
protected override void OnSorting(GridViewSortEventArgs e)
{
SortExpressionEx = e.SortExpression;
SortExpressionStr = e.SortExpression + " " + SortDirectionStr;
OnBind();
if (SortDirectionStr.ToLower() == "asc")
{
SortDirectionStr = "DESC";
}
else
{
SortDirectionStr = "ASC";
}
}
{
SortExpressionEx = e.SortExpression;
SortExpressionStr = e.SortExpression + " " + SortDirectionStr;
OnBind();
if (SortDirectionStr.ToLower() == "asc")
{
SortDirectionStr = "DESC";
}
else
{
SortDirectionStr = "ASC";
}
}
并且增加如下的OnLoad事件
protected override void OnLoad(EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
OnBind();
}
catch
{
}
}
base.OnLoad(e);
}
{
if (!Page.IsPostBack)
{
try
{
OnBind();
}
catch
{
}
}
base.OnLoad(e);
}