Reputation: 21
I have Repeater buttons that i want to change their backcolor on click. The problem is that I dont know how to identify which button is clicked and I cant reach it through the onclick function. Just to make it clear - I want to change the button that has been clicked. It should be like a "selected" button.
THOSE ARE THE BUTTONS
<asp:Repeater ID="rptFillButtonCategory" runat="server">
<ItemTemplate>
<asp:Button ID="FillButton" runat="server" Width="100%" OnClick="ButtonSelectionFill"
CommandArgument='<%#DataBinder.Eval(Container.DataItem, "Id") %>'
Text='<%#DataBinder.Eval(Container.DataItem, "Name") + " for next version" %>'/>
</ItemTemplate>
</asp:Repeater>
This is the on click function
public void ButtonSelectionFill(object o, EventArgs e)
{
Button btn = ((Button)o);
btn.BackColor = System.Drawing.Color.Red;
DropCategory.SelectedValue = Convert.ToInt16(((Button)o).CommandArgument.ToString());
}
Thank you for the help.
Upvotes: 2
Views: 891
Reputation: 13188
This worked:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
<ItemTemplate>
<asp:Button ID="Button1" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "Id") %>' OnClick="Button1_Click" />
</ItemTemplate>
</asp:Repeater>
protected void Button1_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
b.BackColor = System.Drawing.Color.Red;
}
Upvotes: 1