您的位置:首页 > 其它

GridView中点击CheckBox选中一行来改变此行的颜色

2014-05-06 00:00 609 查看
前台:
<asp:TemplateField HeaderText="选择"> 
<ItemStyle HorizontalAlign="Center"/> //居中显示 
<ItemTemplate> 
<asp:CheckBox ID="ckbSelect" runat="server" AutoPostBack="true" oncheckedchanged="ckbSelect_CheckedChanged" /> 
</ItemTemplate> 
</asp:TemplateField>

后台:
/// <summary> 
/// checkbox选中时,改变行颜色 
/// </summary> 
/// <param name="sender"></param> 
/// <param name="e"></param> 
protected void ckbSelect_CheckedChanged(object sender, EventArgs e) 
{ 
for (int i = 0; i < this.gvStudent.Rows.Count; i++) 
{ 
CheckBox cb = (CheckBox)this.gvStudent.Rows[i].FindControl("ckbSelect"); 
if (cb.Checked) 
{ 
this.gvStudent.Rows[i].BackColor = System.Drawing.Color.FromName("#e2eaec"); 
} 
else 
{ 
this.gvStudent.Rows[i].BackColor = System.Drawing.Color.Empty; 
} 
} 
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: