title: How to add class for only the selected link in C# code behind?
body: <p>I have a class called "is-active" and it has a colored arrow that sticks out from the nav into the main content based on which link the user clicked. The code runs a <code>foreach</code> and pulls all the categories from the database. How do I get the "is-active" class to display only for the current link? I know it works since I put it in the <code>openList</code> control and it displayed on all five categories, I just don't know how to get it to display on only the selected category.  </p>
  
  <p>I tried attaching jQuery to do it but adding the <code>linkbutton</code> is done all in the code behind so I am not sure how to attach the two.  Is this the only way or is there another way?</p>
  
  <p>Thank you in advance for your help!</p>
  
  <p>Below is my code for the categories and link button:</p>
  
  <pre><code>protected override void CreateChildControls()
  {
      LiteralControl openingDiv = new LiteralControl("&lt;div id='MainPanel'&gt;");
      LiteralControl closingDiv = new LiteralControl("&lt;/div&gt;");   
  
      this.Controls.Add(openingDiv);
  
      foreach (DataRow dr in ds.Tables[0].Rows)
      {
          LiteralControl openList = new LiteralControl("&lt;li class='" + dr["CategoryColor"].ToString() + "'&gt;");
          LiteralControl closeList = new LiteralControl("&lt;/li&gt;");                
  
          Label lblNumber = new Label();
  
          LinkButton myLinkButton = new LinkButton();
  
          myLinkButton.Text = "&lt;span class='number'&gt;" + dr["CategoryNumber"] + "&lt;/span&gt;"+ dr["CategoryName"].ToString();
          myLinkButton.CommandArgument = dr["Category_ID"].ToString();
          myLinkButton.Click += myLinkButton_Click;
  
          this.Controls.Add(openList);
          this.Controls.Add(myLinkButton);
          this.Controls.Add(closeList);
      }
      this.Controls.Add(closingDiv);
  }
  void myLinkButton_Click(object sender, EventArgs e)
  {
      LinkButton btn = (LinkButton)(sender);
      Session["CategoryID"] = btn.CommandArgument;
  
      Response.Redirect(Request.RawUrl);  
  }
  </code></pre>