title: HtmlTextWriter adding a class to an element which already has one
body: <p>I'm processing some objects in batches and generating some markup for them to be used within a carousel.</p>
  
  <p>When I'm on the last item in the batch i'd like to give that item a class so that I can style it accordingly. </p>
  
  <p>I'm able to give the item an inline style to get it how I want however, if i try to add a class to the element (which has already been given a class) it doesn't show in the markup. Very strange - can you not assign more than one class to an element, does it not append the class to the existing one?</p>
  
  <p>Here is the code I'm working with, hopefully someone can advise:</p>
  
  <pre><code>public static string CreateCarouselMarkup(BrandCollection carouselBrands)
  {
      StringWriter stringWriter = new StringWriter();
      using (HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter))
      {
          //List items
          textWriter.RenderBeginTag(HtmlTextWriterTag.Li);
  
          int idx = 0;
          foreach (Brand brand in carouselBrands)
          {
              idx++;
              textWriter.AddAttribute(HtmlTextWriterAttribute.Href, string.Format("/brands/{0}/", brand.SeoInfo.SeoUrl));
              textWriter.RenderBeginTag(HtmlTextWriterTag.A);
  
              textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "carousel-image");
              textWriter.AddAttribute(HtmlTextWriterAttribute.Src, brand.Logo);
              textWriter.AddAttribute(HtmlTextWriterAttribute.Alt, brand.Title);
  
              //If we are on the last item or last item for this batch
              if (idx == carouselBrands.Count())
              {
                  textWriter.AddAttribute(HtmlTextWriterAttribute.Class, "last-img");
              }
              textWriter.RenderBeginTag(HtmlTextWriterTag.Img);
  
              textWriter.RenderEndTag();//End Img tag
              textWriter.RenderEndTag();//End A tag
          }
  
          textWriter.RenderEndTag();//End Li tag
      }
  
      return stringWriter.ToString();
  }
  </code></pre>
  
  <p>Here is a small sample of the markup that is rendered:</p>
  
  <pre><code>&lt;ul class="bjqs" style="height: 80px; width: 100%; display: block;"&gt;
     &lt;li class="bjqs-slide" style="height: 80px; width: 100%; display: list-item;"&gt;
        &lt;a href="/brands/kaldewei/"&gt;
            &lt;img class="carousel-image" src="/Images/Brands/Logos/kaldewei_logo_02.png" alt="Kaldewei"&gt;
        &lt;/a&gt;
        &lt;a href="/brands/iotti/"&gt;
            &lt;img class="carousel-image" src="/Images/Brands/Logos/Iotti-logo.jpg" alt="Iotti"&gt;
        &lt;/a&gt;
        &lt;a href="/brands/ellis/"&gt;
            &lt;img class="carousel-image" src="/Images/Brands/Logos/Ellis-logo.jpg" alt="Ellis"&gt;
        &lt;/a&gt;
        &lt;a href="/brands/burgbad/"&gt;
            &lt;img class="carousel-image" src="/Images/Brands/Logos/Burgbad-logo.png" alt="Burgbad"&gt;
        &lt;/a&gt;
    &lt;/li&gt;
    &lt;li class="bjqs-slide" style="height: 80px; width: 100%; display: none;"&gt;
       &lt;a href="/brands/pura/"&gt;
           &lt;img class="carousel-image" src="/Images/Brands/Logos/Pura-logo.png" alt="Pura"&gt;  
       &lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I'm expecting the class <code>last-img</code> to be applied to the last images in each batch (i don't want to use a CSS3 property for this). In the above example, it would be applied to <code>burgbad</code> and <code>pura</code>.</p>