- protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
- {
- if (e.Row.RowType == DataControlRowType.DataRow)
- {//如果是数据行
- e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='red';");
- e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
- }
- }
- protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
- {//符合条件的行,改变背景色
- string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "sex"));
- if (lbl == "M")
- {
- e.Row.BackColor = System.Drawing.Color.LimeGreen;
- }
- }
- protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
- {//标题模版里全选按钮
- foreach (GridViewRow gr in GridView1.Rows)
- {
- CheckBox chk = (CheckBox)gr.Cells[4].FindControl("CheckBox1");
- chk.Checked = ((CheckBox)sender).Checked;
- }
- }
GridView技巧1
最新推荐文章于 2019-08-11 12:52:49 发布