GridView固定表头和排序功能
2010-11-21 22:09
375 查看
GridView固定表头功能,兼容IE6,IE7,IE8,firefox
先设置GridView现实表头ShowHeader="True",并且让GridView使用 UseAccessibleHeader 属性来指定数据列表控件是否以可访问的格式呈现其标头
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace KingGridView
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.GridView1.DataSource = GetProducts();
this.GridView1.DataBind();
}
}
private ProductCollection GetProducts()
{
ProductCollection _pc = new ProductCollection();
for (int i = 1; i < 100; i++)
{
_pc.Add(
new Product { id = i.ToString(), categoryid = i.ToString(), createtime = System.DateTime.Now.ToString(),
productid = i.ToString(), productname = i.ToString(), strdesc = i.ToString(), strggxh = i.ToString() }
);
}
return _pc;
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
this.GridView1.UseAccessibleHeader = true;
this.GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
public class ProductCollection : ICollection<Product>
{
List<Product> _Products;
public ProductCollection()
{
_Products = new List<Product>();
}
#region ICollection<Product> Members
public void Add(Product item)
{
_Products.Add(item);
}
public void Clear()
{
_Products.Clear();
}
public bool Contains(Product item)
{
return _Products.Contains(item);
}
public void CopyTo(Product[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public int Count
{
get { return _Products.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public bool Remove(Product item)
{
return _Products.Remove(item);
}
#endregion
#region IEnumerable<Product> Members
public IEnumerator<Product> GetEnumerator()
{
return _Products.GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _Products.GetEnumerator();
}
#endregion
}
public class Product
{
public string id
{
get;
set;
}
public string productid
{
get;
set;
}
public string productname
{
get;
set;
}
public string categoryid
{
get;
set;
}
public string strggxh
{
get;
set;
}
public string createtime
{
get;
set;
}
public string strdesc
{
get;
set;
}
}
}
先设置GridView现实表头ShowHeader="True",并且让GridView使用 UseAccessibleHeader 属性来指定数据列表控件是否以可访问的格式呈现其标头
代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace KingGridView
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.GridView1.DataSource = GetProducts();
this.GridView1.DataBind();
}
}
private ProductCollection GetProducts()
{
ProductCollection _pc = new ProductCollection();
for (int i = 1; i < 100; i++)
{
_pc.Add(
new Product { id = i.ToString(), categoryid = i.ToString(), createtime = System.DateTime.Now.ToString(),
productid = i.ToString(), productname = i.ToString(), strdesc = i.ToString(), strggxh = i.ToString() }
);
}
return _pc;
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
this.GridView1.UseAccessibleHeader = true;
this.GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
}
}
public class ProductCollection : ICollection<Product>
{
List<Product> _Products;
public ProductCollection()
{
_Products = new List<Product>();
}
#region ICollection<Product> Members
public void Add(Product item)
{
_Products.Add(item);
}
public void Clear()
{
_Products.Clear();
}
public bool Contains(Product item)
{
return _Products.Contains(item);
}
public void CopyTo(Product[] array, int arrayIndex)
{
throw new NotImplementedException();
}
public int Count
{
get { return _Products.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public bool Remove(Product item)
{
return _Products.Remove(item);
}
#endregion
#region IEnumerable<Product> Members
public IEnumerator<Product> GetEnumerator()
{
return _Products.GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _Products.GetEnumerator();
}
#endregion
}
public class Product
{
public string id
{
get;
set;
}
public string productid
{
get;
set;
}
public string productname
{
get;
set;
}
public string categoryid
{
get;
set;
}
public string strggxh
{
get;
set;
}
public string createtime
{
get;
set;
}
public string strdesc
{
get;
set;
}
}
}
相关文章推荐
- 通过客户端扩展实现固定GridView表头功能
- 使用DevExpress.XtraGrid.Views.Grid.GridView 点击表头排序时焦点固定到所选中行的行号,而不是固定到这条数据
- 通过客户端扩展实现固定GridView表头功能
- ASP.net中Gridview修改表头后没有排序功能的解决方法
- bootstrap点击表头实现排序功能
- GridView固定表头
- (DevExpress2011控件教程)ASPxGridView 范例4 :ASPxGridView 行选择、多表头设计、数据导出、主表细表等功能实现
- Asp.net 2.0 自定义控件开发[实现GridView多行表头固定表体滚动效果][示例代码下载]
- GridView固定表头
- GridView固定表头 - 动态创建模板列 、构造模板选择列触发js方法
- 在asp.net中实现Gridview 表头固定
- gridview手动添加排序功能总结
- 创建表头固定,表体可滚动的GridView
- (分页、排序等)asp.net 2.0下一个标准GRIDVIEW功能的实现
- 固定GridView 的表头和某几列
- GridView列的排序功能
- javascript 带有滚动条的表格,标题固定,带排序功能.
- GridView 表头固定的一种实现方法
- ASP中GridView点击列头排序的功能
- GridView固定表头的方法两则