title: How to create Dropdownlist using XSLT C#?
body: <p>I am working on project used xslt file to display repeated items. as below:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output omit-xml-declaration="yes" indent="yes" /&gt;
    &lt;xsl:param name="BasePath" select="/" /&gt;
    &lt;xsl:param name="OffersPerPage" select="4" /&gt;
    &lt;xsl:template match="/" xml:space="default"&gt;
     &lt;div class="offers_section"&gt;
  &lt;script&gt;
   $(document).ready(function() {
     $(".offers_page").hide();
     $("#OfferPage1").show();
    });
   function OffersPageChange(CurrentPage, NewPage)
    {
     $("#OfferPage" + CurrentPage).hide();
  $("#OfferPage" + NewPage).show();
   $("$offers_section").focus();
   return false;
   }
  &lt;/script&gt;
  
  &lt;xsl:choose&gt;
    &lt;xsl:when test="count(//Offers/Offer) &amp;gt; 0"&gt;
  
    &lt;xsl:for-each select="//Offers/Offer[(position()) mod $OffersPerPage = 1 or position = 1]"&gt;
      &lt;xsl:variable name="page" select="position()" /&gt;
      &lt;xsl:variable name="lastpage" select="last()" /&gt;
  
      &lt;div class="offers_page"&gt;&lt;xsl:attribute name="id"&gt;OfferPage&lt;xsl:value-of select="$page" /&gt;&lt;/xsl:attribute&gt;
        &lt;div class="offers_paging"&gt;
          &lt;xsl:if test="$page &amp;gt; 1"&gt;
          &lt;a href="#"&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="$page - 1" /&gt;)&lt;/xsl:attribute&gt;&amp;lt; Previous&lt;/a&gt;
          &lt;/xsl:if&gt;
  
          &lt;xsl:if test="$page &amp;lt; $lastpage"&gt;
          &lt;a href="#"&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="$page + 1" /&gt;)&lt;/xsl:attribute&gt;Next &amp;gt;&lt;/a&gt;
          &lt;/xsl:if&gt;
          &lt;br /&gt;&lt;br /&gt;
  
          &lt;xsl:if test="$lastpage != 1"&gt;
            &lt;xsl:for-each select="//Offers/Offer"&gt;
              &lt;xsl:if test="(position() - 1) mod $OffersPerPage = 0"&gt;
                &lt;a href="#"&gt;&lt;xsl:attribute name="class"&gt;&lt;xsl:choose&gt;&lt;xsl:when test="(position() - 1) div $OffersPerPage + 1 = $page"&gt;offers_page_number_active&lt;/xsl:when&gt;&lt;xsl:otherwise&gt;offers_page_number&lt;/xsl:otherwise&gt;&lt;/xsl:choose&gt;&lt;/xsl:attribute&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /&gt;)&lt;/xsl:attribute&gt;&lt;xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /&gt;&lt;/a&gt;
              &lt;/xsl:if&gt;
            &lt;/xsl:for-each&gt;
            &lt;br /&gt;&lt;br /&gt;
          &lt;/xsl:if&gt;
        &lt;/div&gt;
  
        &lt;xsl:for-each select=". | following-sibling::Offer[(position()) &amp;lt; $OffersPerPage]" &gt;
          &lt;div class="offers_offer"&gt;
            &lt;h2&gt;&lt;xsl:value-of select="Partner" /&gt;&lt;/h2&gt;
  
            &lt;xsl:if test="ImageSource != ''"&gt;
            &lt;div class="offers_image_container"&gt;
              &lt;div class="offers_image"&gt;
                &lt;img width="100%"&gt;&lt;xsl:attribute name="src"&gt;&lt;xsl:value-of select="$BasePath" /&gt;portals/&lt;xsl:value-of select="ImageSource" /&gt;&lt;/xsl:attribute&gt;&lt;/img&gt;
              &lt;/div&gt;
              &lt;div class="offers_image_overlay"&gt;
                &lt;img width="100%" height="33" alt=""&gt;&lt;xsl:attribute name="src"&gt;&lt;xsl:value-of select="$BasePath" /&gt;portals/_default/skins/images/offer%20top%20swoop.png&lt;/xsl:attribute&gt;&lt;/img&gt;
                &lt;img width="100%" height="126" style="position:absolute;bottom:0;left:0;right:0;" alt=""&gt;&lt;xsl:attribute name="src"&gt;&lt;xsl:value-of select="$BasePath" /&gt;portals/_default/skins/images/offer%20bottom%20swoop.png&lt;/xsl:attribute&gt;&lt;/img&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="Description != ''"&gt;
            &lt;div class="offers_description"&gt;
              &lt;xsl:value-of select="Description" /&gt;&lt;br /&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="LegalInformation != '' and LegalOnOfferPage = 'True'"&gt;
            &lt;div class="offers_legal"&gt;
              &lt;xsl:value-of select="LegalInformation" /&gt;&lt;br /&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="Facebook != '' or Twitter != ''"&gt;
            &lt;div class="offers_social_media"&gt;
              Follow us on:&lt;br /&gt;
              &lt;div class="social_media_links"&gt;
                &lt;xsl:if test="Facebook != ''"&gt;
                &lt;a class="facebook_logo" style="float:none;" target="_blank" title="Facebook"&gt;&lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="Facebook" /&gt;&lt;/xsl:attribute&gt;&lt;/a&gt;
                &lt;/xsl:if&gt;
                &lt;xsl:if test="Twitter != ''"&gt;
                &lt;a class="twitter_logo" style="float:none;" target="_blank" title="Twitter"&gt;&lt;xsl:attribute name="href"&gt;https://www.twitter.com/&lt;xsl:value-of select="Twitter" /&gt;&lt;/xsl:attribute&gt;&lt;/a&gt;
                &lt;/xsl:if&gt;
              &lt;/div&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="UrlText != ''"&gt;
            &lt;div class="offers_url"&gt;
            &lt;a target="_blank"&gt;&lt;xsl:attribute name="href"&gt;&lt;xsl:value-of select="Url" /&gt;&lt;/xsl:attribute&gt;&lt;xsl:value-of select="UrlText" /&gt;&lt;/a&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="Email != ''"&gt;
            &lt;div class="offers_email"&gt;
            Email: &lt;a&gt;&lt;xsl:attribute name="href"&gt;mailto:&lt;xsl:value-of select="Email" /&gt;&lt;/xsl:attribute&gt;&lt;xsl:value-of select="Email" /&gt;&lt;/a&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
  
            &lt;xsl:if test="Phone != ''"&gt;
            &lt;div class="offers_phone"&gt;
            Tel no: &lt;strong&gt;&lt;xsl:value-of select="Phone" /&gt;&lt;/strong&gt;
            &lt;/div&gt;
            &lt;/xsl:if&gt;
          &lt;/div&gt;
        &lt;/xsl:for-each&gt;
        &lt;xsl:if test="$lastpage &amp;gt; 1"&gt;
  
        &lt;div class="offers_paging"&gt;
          &lt;xsl:if test="$lastpage != 1"&gt;
            &lt;xsl:for-each select="//Offers/Offer"&gt;
              &lt;xsl:if test="(position() - 1) mod $OffersPerPage = 0"&gt;
                &lt;a href="#"&gt;&lt;xsl:attribute name="class"&gt;&lt;xsl:choose&gt;&lt;xsl:when test="(position() - 1) div $OffersPerPage + 1 = $page"&gt;offers_page_number_active&lt;/xsl:when&gt;&lt;xsl:otherwise&gt;offers_page_number&lt;/xsl:otherwise&gt;&lt;/xsl:choose&gt;&lt;/xsl:attribute&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /&gt;)&lt;/xsl:attribute&gt;&lt;xsl:value-of select="(position() - 1) div $OffersPerPage + 1" /&gt;&lt;/a&gt;
              &lt;/xsl:if&gt;
            &lt;/xsl:for-each&gt;
            &lt;br /&gt;&lt;br /&gt;
          &lt;/xsl:if&gt;
  
          &lt;xsl:if test="$page &amp;gt; 1"&gt;
          &lt;a href="#"&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="$page - 1" /&gt;)&lt;/xsl:attribute&gt;&amp;lt; Previous&lt;/a&gt;
          &lt;/xsl:if&gt;
  
          &lt;xsl:if test="$page &amp;lt; $lastpage"&gt;
          &lt;a href="#"&gt;&lt;xsl:attribute name="onclick"&gt;return OffersPageChange(&lt;xsl:value-of select="$page" /&gt;, &lt;xsl:value-of select="$page + 1" /&gt;)&lt;/xsl:attribute&gt;Next &amp;gt;&lt;/a&gt;
          &lt;/xsl:if&gt;
        &lt;/div&gt;
        &lt;/xsl:if&gt;
      &lt;/div&gt;
    &lt;/xsl:for-each&gt;
    &lt;/xsl:when&gt;
    &lt;xsl:otherwise&gt;
      &lt;div class="offers_not_available"&gt;
        Sorry, no offers are currently available in this category
      &lt;/div&gt;
    &lt;/xsl:otherwise&gt;
  &lt;/xsl:choose&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>Code Behind Code is :</p>
  
  <pre class="lang-xml prettyprint-override"><code> void Load_Category(int CategoryId)
      {
          string skinPath = PortalSettings.ActiveTab.SkinPath;
  
          XDocument XDocOffers = new XDocument(new XElement("Offers"));
          SqlDataProvider provider = new SqlDataProvider();
          SqlConnection SQLConnection = new SqlConnection(provider.ConnectionString);
          SQLConnection.Open();
  
          SqlConnection SQLConnectionAnswers = new SqlConnection(provider.ConnectionString);
          SQLConnectionAnswers.Open();
  
          SqlCommand sqlComm = new SqlCommand("CIDOTOffersGetOffersByCategory", SQLConnection);
          sqlComm.CommandType = CommandType.StoredProcedure;
  
          sqlComm.Parameters.Add(new SqlParameter("@CategoryId", SqlDbType.Int)).Value = CategoryId;
  
          SqlDataReader OffersReader = sqlComm.ExecuteReader();
  
          string OfferId;
          string Partner;
          string Description;
          string ImageSource;
          string Url;
          string UrlText;
          string Email;
          string Phone;
          string LegalInformation;
          string Facebook;
          string Twitter;
          string LegalOnOfferPage;
          string onclick;
          string Emailonclick;
          while (OffersReader.Read())
          {
              OfferId = OffersReader["OfferId"].ToString();
              Partner = OffersReader["Partner"].ToString();
              Description = OffersReader["Description"].ToString();
              ImageSource = OffersReader["ImageSource"].ToString();
              Url = OffersReader["Url"].ToString();
              UrlText = OffersReader["UrlText"].ToString();
              Email = OffersReader["Email"].ToString();
              Phone = OffersReader["Phone"].ToString();
              LegalInformation = OffersReader["LegalInformation"].ToString();
              Facebook = OffersReader["Facebook"].ToString();
              Twitter = OffersReader["Twitter"].ToString();
              LegalOnOfferPage = OffersReader["LegalOnOfferPage"].ToString();
              onclick = "_gaq.push(['_trackEvent', 'Book Now', 'click', '" + Partner + "']);";
              Emailonclick = "_gaq.push(['_trackEvent', 'Email', 'click', '" + Email + "']);";
              XElement NextOffer =
                new XElement("Offer",
                  new XElement("OfferId", OfferId),
                  new XElement("Partner", Partner),
                  new XElement("Description", Description),
                  new XElement("ImageSource", ImageSource),
                  new XElement("Url", Url),
                  new XElement("UrlText", UrlText),
                  new XElement("Email", Email),
                  new XElement("Phone", Phone),
                  new XElement("LegalInformation", LegalInformation),
                  new XElement("Facebook", Facebook),
                  new XElement("Twitter", Twitter),
                  new XElement("LegalOnOfferPage", LegalOnOfferPage),
                  new XElement("onclick", onclick),
                  new XElement("Emailonclick", Emailonclick)
                );
  
              XDocOffers.Element("Offers").Add(NextOffer);
          }
  
          OffersReader.Close();
          SQLConnection.Close();
  
          string XSLTFile = Server.MapPath(skinPath + "xslt/offers.xslt");
          if (File.Exists(XSLTFile))
          {
              StringWriter XSLTOutput = new StringWriter();
              XmlWriter XMLOutput = XmlWriter.Create(XSLTOutput);
  
              // Load the style sheet.
              XslCompiledTransform xslt = new XslCompiledTransform();
              xslt.Load(XSLTFile);
  
              XsltArgumentList ArgumentsQA = new XsltArgumentList();
  
              if (Settings.ContainsKey("OffersPerPage"))
              {
                  ArgumentsQA.AddParam("OffersPerPage", "", Settings["OffersPerPage"].ToString());
              }
              else
              {
                  ArgumentsQA.AddParam("OffersPerPage", "", "4");
              }
  
              ArgumentsQA.AddParam("BasePath", "", "/");
  
              // Execute the transform and output the results to a writer.
              xslt.Transform(XDocOffers.CreateReader(), ArgumentsQA, XMLOutput);
  
              //Output.Controls.Add(new LiteralControl(XSLTOutput.ToString().Replace("&amp;amp;", "&amp;")));
              Output.Controls.Add(new LiteralControl(HttpUtility.HtmlDecode(XSLTOutput.ToString())));
  
          }
          else
          {
              Output.Controls.Add(new LiteralControl("Cannot find XSLT file"));
          }
      }
  </code></pre>
  
  <p>I have never worked with xslt before, now i want to add a dropdownlist to the page and need to create a search for the selected value from the repeated items in the page body. </p>
  
  <p>My questions are:</p>
  
  <ol>
  <li><p>how can i create a dropdownlist in xslt. 
  i have tried the below links but it didn't work for me.
  <a href="http://www.codeproject.com/Articles/8574/Generate-dynamic-ASP-NET-pages-by-using-XML-and-XS" rel="nofollow">Generate dynamic dropdown in xslt using c#</a></p></li>
  <li><p>how to create a event that will search from repeated items. is there any way by which i can call the dropdown's selectedindex change event.?</p></li>
  </ol>
  
  <p>please help.</p>