简体   繁体   中英

add div to page from the code behind Asp.net/C#

Hello I have a item list that shows on my asp.net page like this:

    <div class="search-result-item">

            <div class="image">
                <img src="images/1.png"/>
            </div>
            <div class="logo">
                <img src="images/logo.png"/>
            </div>
            <div class="header">
                Title
            </div>
            <div class="message">
                Message
            </div>
            <div class="keywords">
                key1 | key2 | key3
            </div>

            <div class="links">
                <a href="link.html">Go to</a>
            </div>

        </div>

This shows a predefined layout for an item on the page.

Items are generated in the code behind.

I want for each item to create a div like the one above on the page. How can I do that using the code behind?

Thanks a lot

You create a Control and add it to your page.

There are a large range of controls, but if you want that exact markup, and don't need any server-side processing, the LiteralControl control is probably the most appropriate.

Use a repeater control You create a control that basically connects to datasource and then repeats info based on the data. Very crude description sorry. Look at it on Google.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM