repeter选中行修改颜色
前台界面关键代码:
<ItemTemplate> <tr runat="server" id="tabtr1"><td style=" text-align:center;"><%# Container.ItemIndex + 1 + (pagerBasic.CurrentPageIndex - 1) * 10%></td>
在界面给tr加上id便于后台获取。
<td style=" text-align:center;">
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("mid")%>' />
<asp:CheckBox ID="cbxChild" runat="server" AutoPostBack="True"
oncheckedchanged="chk_CheckedChanged" />
</td>
</tr></ItemTemplate>
用CheckBox进行选中变色。
后台关键代码:
protected void chk_CheckedChanged(object sender, EventArgs e)
{
for (int i = 0; i < Repeater1.Items.Count; i++)
{
Boolean isChecked = ((CheckBox)Repeater1.Items[i].FindControl("cbxChild")).Checked;
if (isChecked)
{
HtmlTableRow col = (HtmlTableRow)Repeater1.Items[i].FindControl("tabtr1");
col.BgColor = "#5F9EA0";
}
else
{
//#c7c7c7
HtmlTableRow col = (HtmlTableRow)Repeater1.Items[i].FindControl("tabtr1");
col.BgColor = "#ffffff";
}
}
}