GridView带有上下箭头的多列排序
2008-08-21 09:38
399 查看
#region 私有变量
protected string JS = "";
string SortExpression = "";//排序表达式
string SortDirection = "";//排序方向
#endregion
#region 事件
/// <summary>
/// 生成排序列旁边的小箭头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
{
string s1 = ((LinkButton)tc.Controls[0]).Text;
((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
}
if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
if (((LinkButton)tc.Controls[0]).CommandArgument == SortExpression)
{
string s2 = ((LinkButton)tc.Controls[0]).Text;
if (SortDirection == "DESC")
{
((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
}
}
}
}
}
}
/// <summary>
/// 排序方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvData_Sorting(object sender, GridViewSortEventArgs e)
{
//得到排序条件
SortExpression = e.SortExpression.ToString();
//设置排序为升序
SortDirection = "ASC";
//当当前排序为升序时,修改成降序
if (this.gridView.Attributes["SortDirection"] == "ASC")
{
SortDirection = "DESC";
}
//设置GridView的排序状态
this.gridView.Attributes["SortExpression"] = SortExpression;
this.gridView.Attributes["SortDirection"] = SortDirection;
BindGridView();
}
#endregion
#region 私有方法
/// <summary>
/// 根据排序条件重新绑定GridView
/// </summary>
private void BindGridView()
{
string sortExpression = this.gridView.Attributes["SortExpression"];
string sortDirection = this.gridView.Attributes["SortDirection"];
if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
{
DataSource.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
}
this.gridView.DataSource = DataSource;
this.gridView.DataBind();
}
#endregion
以上就是全部的代码~
protected string JS = "";
string SortExpression = "";//排序表达式
string SortDirection = "";//排序方向
#endregion
#region 事件
/// <summary>
/// 生成排序列旁边的小箭头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvData_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
foreach (TableCell tc in e.Row.Cells)
{
if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
{
string s1 = ((LinkButton)tc.Controls[0]).Text;
((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
}
if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
if (((LinkButton)tc.Controls[0]).CommandArgument == SortExpression)
{
string s2 = ((LinkButton)tc.Controls[0]).Text;
if (SortDirection == "DESC")
{
((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
}
}
}
}
}
}
/// <summary>
/// 排序方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvData_Sorting(object sender, GridViewSortEventArgs e)
{
//得到排序条件
SortExpression = e.SortExpression.ToString();
//设置排序为升序
SortDirection = "ASC";
//当当前排序为升序时,修改成降序
if (this.gridView.Attributes["SortDirection"] == "ASC")
{
SortDirection = "DESC";
}
//设置GridView的排序状态
this.gridView.Attributes["SortExpression"] = SortExpression;
this.gridView.Attributes["SortDirection"] = SortDirection;
BindGridView();
}
#endregion
#region 私有方法
/// <summary>
/// 根据排序条件重新绑定GridView
/// </summary>
private void BindGridView()
{
string sortExpression = this.gridView.Attributes["SortExpression"];
string sortDirection = this.gridView.Attributes["SortDirection"];
if ((!string.IsNullOrEmpty(sortExpression)) && (!string.IsNullOrEmpty(sortDirection)))
{
DataSource.DefaultView.Sort = string.Format("{0} {1}", sortExpression, sortDirection);
}
this.gridView.DataSource = DataSource;
this.gridView.DataBind();
}
#endregion
以上就是全部的代码~
相关文章推荐
- Gridview自定义排序且显示上下箭头
- GridView实现自动排序带上下箭头
- GridView实现自动排序带上下箭头
- GridView排序加上下箭头(2)
- 艾伟:Gridview自定义排序且显示上下箭头
- Gridview自定义排序且显示上下箭头
- GridView实现自动排序带上下箭头
- 分享GridView 排序上下箭头的实现和鼠标移上行的变色及序号列上带小三角形
- [转]Gridview自定义排序且显示上下箭头
- Gridview自定义排序且显示上下箭头
- php上下箭头排序
- 功能齐全的GridView!Asp.Net中GridView的自定义分页,带箭头的排序,鼠标高亮每一行,无数据时的提醒,点击Button弹出框!
- gridview排序加箭头(二)
- php上下箭头排序
- php中一个用箭头实现的上下排序的函数
- GridView系列(一)排序列头加箭头
- gridview 排序时候显示箭头
- 重写gridview,支持list和dataset自动排序,带排序箭头,顺便把自动翻页也加进去了.
- 扩展GridView控件以包含一个与排序相关的箭头标记
- gridview 给排序字段添加箭头