Gridview checkBox选中行的背景颜色
现在我做一个在Gridview 里面有checkbox选择项,我想让他选择一项,背景颜色变化成一个颜色,请大家多多指教:
下面是我写的一部分代码
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
int i;
for (i = 0; i < this.GridView1.Rows.Count;i++ )
{
CheckBox chx = (CheckBox)this.GridView1.Rows[i].FindControl("CheckBox1");
if (chx.Checked)
{
Response.Write("你选择了行");
this.GridView1.Rows[i].Attributes.Add("", "this.style.backgroundColor=blue");
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=blue");
}
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count+1; i++)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#00A9FF'");
}
}
}