I have a method that loops through a list and creates Links using the LinkButton control. For the purpose of this question, assume that it is a list of colors and that I have 5 colors: red, green, blue, red, and yellow. Here is a code snippet of how I am creating the links and adding the event handler.
foreach(color in colors)
{
LinkButton lb = new LinkButton();
lb.Text = color.name;
lb.Click += new System.EventHandler(this.colorClick);
lb.CommandName = "CommandName";
lb.CommandArgument = "CommandArgument";
lb.ID = color.Id;
}
In the even handler, colorClick, I am bolding the clicked link by doing the following:
protected void colorClick(object o, EventArgs e)
{
LinkButton lnk = (LinkButton)o;
lnk.Style["font-weight"] = "bold";
//Process clicked link.
}
The above code works fine as far as bolding the currently clicked link, the problem I run into is that assume that the link clicked was Red, so Red would be bold, if I click Blue, I want to bold the link Blue, but unbold Red. I have tried:
lnk.Style["font-weight"] = "normal";
lnk.Font.Bold = "false";
but, it occured to me that while the above maybe correct, I am doing it in the wrong spot (colorClick). What I was thinking is that I probably have to remember the previously clicked link and unbold that one, but I am unsure of how to do that.