locked
how can i replicate this piece of html inside code behind c#? RRS feed

  • Question

  • So I have this piece of code in the aspx

        <div class="imgGrid" style="float:left">
            <a href="XXXXXX" class="play_youtube iframe" title="XXXXXXXXXXX">
                <img src="XXXXXX" class="thumbnail" style="width:80px; height:55px; margin-right:10px; margin-bottom:10px;" border="0" />
                </a>
            </div>

    I need to replicate it while I run through an array of videos using a foreach loop, i then get the data seen as x's in the code above and place it in.

    How can this be done?

    Thursday, May 21, 2015 2:10 PM

Answers

  • Hi Noxiann,

    Welcome to MSDN forum.

    From your description, this thread is related to ASP.NET, ASP.NET forum is more suitable for it ,I would like to suggest to ASP.NET forum.http://forums.asp.net/

    This moederator and community will be gald to help you.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Friday, May 22, 2015 6:29 AM
    • Proposed as answer by Fouad Roumieh Friday, May 22, 2015 6:44 AM
    • Marked as answer by Just Karl Friday, May 29, 2015 3:57 PM
    Friday, May 22, 2015 6:29 AM

All replies

  • I suggest that you create tags inside your html, and replace those tags with its real values when looping. I don't have clue about your loop, but to make my idea close see below:

    string href = "www.xyz.com";
                string title = "MY title";
                string src = "www.src.com";
                string template = "<div class='imgGrid' style='float:left'>" +
                "<a href='$href$' class='play_youtube iframe' title='$title$'>" +
                    "<img src='$src$' class='thumbnail' style='width:80px; height:55px; margin-right:10px; margin-bottom:10px;' border='0' />" +
                    "</a>" +
        "</div>";
    
                template = template.Replace("$href$", href).Replace("$title$", title).Replace("$src$", src);


    Fouad Roumieh

    Thursday, May 21, 2015 6:11 PM
  • Is there a particular reason you're using code to do this?

    Because I would have thought this is an obvious use of the repeater control bound to a List<t>

    A repeater looks like:

    <asp:Repeater id="myLinks" runat="server">
       <ItemTemplate>
          <asp:HyperLink runat="server" NavigateUrl='<%# ... %>' Text=... etc etc/>
       </ItemTemplate>
    </asp:Repeater>

    https://msdn.microsoft.com/en-us/library/x8f2zez5(v=vs.140).aspx

    https://msdn.microsoft.com/en-us/magazine/cc163780.aspx

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396



    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Thursday, May 21, 2015 7:33 PM
  • Hi Noxiann,

    Welcome to MSDN forum.

    From your description, this thread is related to ASP.NET, ASP.NET forum is more suitable for it ,I would like to suggest to ASP.NET forum.http://forums.asp.net/

    This moederator and community will be gald to help you.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Friday, May 22, 2015 6:29 AM
    • Proposed as answer by Fouad Roumieh Friday, May 22, 2015 6:44 AM
    • Marked as answer by Just Karl Friday, May 29, 2015 3:57 PM
    Friday, May 22, 2015 6:29 AM