Add a <div> to each <li> - Htmlgenericcontrol tag

Asked

Viewed 98 times

1

I am reading an RSS XML and adding each news to a tag <li>

I need every tag <li> stay within a tag <div>, how can I do this through Htmlgenericcontrol?

That way

              <div>
                <li><span>Ações contra dengue prosseguem em Araruama &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Laboratório em Campinas identifica 'impressão digital' do vírus da zika &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Agentes arrombam casas fechadas em Recife contra o Aedes aegypti &ndash; <a href="#">Leia mais</a></span></li>
            </div>
            <div>
                <li><span>Universidade de Sorocaba coordena três estudos sobre o Aedes aegypti &ndash; <a href="#">Leia mais</a></span></li>
            </div>

Follow the code below:

    private void AddMenuItem()
{

    XmlDocument rssXmlDoc = new XmlDocument();

    // Load the RSS file from the RSS URL
    rssXmlDoc.Load("http://g1.globo.com/dynamo/luta-contra-a-dengue/rss.xml");

    // Parse the Items in the RSS file
    XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

    StringBuilder rssContent = new StringBuilder();

    // Iterate through the items in the RSS file
    foreach (XmlNode rssNode in rssNodes)
    {

        XmlNode rssSubNode = rssNode.SelectSingleNode("title");
        string title = rssSubNode != null ? rssSubNode.InnerText : "";

        rssSubNode = rssNode.SelectSingleNode("link");
        string link = rssSubNode != null ? rssSubNode.InnerText : "";



        HtmlGenericControl li = new HtmlGenericControl("li");
        noticias.Controls.Add(li);

        HtmlGenericControl span = new HtmlGenericControl("span");
        span.InnerText = title;           

        HtmlGenericControl anchor = new HtmlGenericControl("a");
        anchor.Attributes.Add("href", link);
        anchor.InnerText = "Leia Mais";

        li.Controls.Add(span);
        li.Controls.Add(anchor);

    }


}

1 answer

-1


The solution is easier than I thought. I added

HtmlGenericControl div = new HtmlGenericControl("div");
noticias.Controls.Add(div);

Then at the end

div.Controls.Add(li);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.