It's a little complicated, but not too bad:
1) Add this line to your CreateButtons method:
btn.Width = Unit.Pixel(50);
btn.ID = string.Format("butDynamic{0}", i);
pnlButtons.Controls.Add(btn);
2) Add a Hidden field to your Page:
<asp:HiddenField ID="PressedButton" runat="server" />
3) Add this code to your Button handler:
void btn_Click(object sender, EventArgs e)
{
Button b = sender as Button;
if (b != null)
{
PressedButton.Value = b.ID;
}
}
4) Add this code to your SelectedIndexChanged event:
if (PressedButton.Value != null)
{
Button b = (Button) (pnlButtons.FindControl((string) PressedButton.Value));
if (b != null)
{
b.BackColor = System.Drawing.Color.Red;
}
}
Do bear in mind that you only get the Selected Index changed event when the RadioListBox loses the focus - NOT when the user makes a selection.