<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<asp:Button ID="Button2" runat="server" CommandName="SaveId" CommandArgument='<%#Eval("subid") %>' OnClick="lnkSubject_CLick" Text='<%#Eval("subject") %>' />
</ItemTemplate>
</asp:Repeater>
我需要更改用户点击的转发器内的按钮的前景色。 当用户单击不同的按钮时,所有单击的按钮都保持蓝色。 我只希望当前点击的按钮保持蓝色。
protected void lnkSubject_CLick(object sender, EventArgs e)
{
Button Button2 = (Button)sender;
Button2.ForeColor = System.Drawing.Color.Blue;
Button2.BackColor = System.Drawing.Color.White;
Button2.BorderColor = System.Drawing.Color.Blue;
}
答案 0 :(得分:0)
试试这个: -
protected void lnkSubject_CLick(object sender, EventArgs e)
{
Button Button2 = (Button)sender;
foreach (RepeaterItem item in Repeater1.Items)
{
Button otherButton = (Button)item.FindControl("Button2");
if (otherButton.ForeColor != Color.Empty )
{
otherButton.ForeColor = Color.Empty;
otherButton.BackColor = Color.Empty;
otherButton.BorderColor = Color.Empty;
}
}
Button2.ForeColor = Color.Blue;
Button2.BackColor = Color.White;
Button2.BorderColor = Color.Blue;
}
在这里,我只检查ForeColor
属性,如果你想也可以检查其他属性。