您的位置:首页 > Web前端 > JQuery

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: