Jquery实现GridView隔行变色,鼠标经过变色,单击或者选中变色
2010-12-01 13:56
771 查看
在Jquery实现GridView实现全选的功能基础上(Jquery实现Gridview全选功能 ),再做扩展,实现GridView隔行变色,鼠标经过变色,单击事件或者checkbox选中时变色功能
代码
public partial class JqueryGridView : 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 < 15; i++)
{
_pc.Add(
new Product { id = i.ToString(), categoryid = i.ToString(), createtime = System.DateTime.Now.ToString(),
productid = i.ToString(), productname = i.ToString() }
);
}
return _pc;
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
this.GridView1.UseAccessibleHeader = true;
this.GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
this.GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
}
protected void btnServer_Click(object sender, EventArgs e) {
this.txtResult.Text = string.Empty;
if (GridView1.Rows.Count > 0) {
foreach (GridViewRow row in GridView1.Rows) {
HtmlInputCheckBox _chkItem = (HtmlInputCheckBox)row.FindControl("chkItem");
if (_chkItem != null&&_chkItem.Checked) {
this.txtResult.Text +=_chkItem.Value+",";
}
}
if (this.txtResult.Text.Length > 0) {
this.txtResult.Text = this.txtResult.Text.Substring(0, this.txtResult.Text.Length - 1);
}
}
}
}
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 createtime
{
get;
set;
}
}
代码
public partial class JqueryGridView : 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 < 15; i++)
{
_pc.Add(
new Product { id = i.ToString(), categoryid = i.ToString(), createtime = System.DateTime.Now.ToString(),
productid = i.ToString(), productname = i.ToString() }
);
}
return _pc;
}
protected void GridView1_PreRender(object sender, EventArgs e)
{
this.GridView1.UseAccessibleHeader = true;
this.GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;
this.GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
}
protected void btnServer_Click(object sender, EventArgs e) {
this.txtResult.Text = string.Empty;
if (GridView1.Rows.Count > 0) {
foreach (GridViewRow row in GridView1.Rows) {
HtmlInputCheckBox _chkItem = (HtmlInputCheckBox)row.FindControl("chkItem");
if (_chkItem != null&&_chkItem.Checked) {
this.txtResult.Text +=_chkItem.Value+",";
}
}
if (this.txtResult.Text.Length > 0) {
this.txtResult.Text = this.txtResult.Text.Substring(0, this.txtResult.Text.Length - 1);
}
}
}
}
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 createtime
{
get;
set;
}
}
相关文章推荐
- 实现表格鼠标经过变色,点击变色并选中项目
- jQuery实现table隔行换色和鼠标经过变色
- jQuery实现table隔行换色和鼠标经过变色的两种方法
- 【修改】 Jquery实现边输入边查询,仿百度,并可以选择查询的值赋到输入框。选中行变色,鼠标变手型
- JQuery实现表格隔行变色,鼠标经过的行放大显示
- jQuery实现table隔行换色和鼠标经过变色
- jQuery实现table表格隔行换色鼠标经过变色
- jQuery实现table隔行换色和鼠标经过变色
- jquery实现table鼠标经过变色代码
- jQuery实现table隔行换色和鼠标经过变色
- jQuery实现table隔行换色和鼠标经过变色
- jQuery实现table隔行换色和鼠标经过变色
- 用jquery实现单双行变色以及鼠标经过时也同时变色
- jQuery实现table表格隔行换色鼠标经过变色
- jQuery实现table隔行换色和鼠标经过变色的两种方法
- jquery实现table鼠标经过变色代码
- jQuery实现鼠标单击网页文字后在文本框显示的方法
- jquery实现TAB选项卡鼠标经过带延迟效果的方法
- CSS+DIV实现鼠标经过背景变色
- JQuery实现鼠标经过事件