简体   繁体   English

定位代码在li中生成datalist项目

[英]positioning code generated datalist items within li

My website has the following: 我的网站有以下内容:

<li class="tile lower-boxes icon_email" data-target-activation="click" data-target="news">
          <div>
            <h2>News 1       
            </h2><h3>24</h3>
          </div>
        </li>

          <li class="tile lower-boxes icon_email" data-target-activation="click" data-target="news">
          <div>
            <h2>News 2</h2><h3>24</h3>
          </div>
        </li>

          <li class="tile lower-boxes icon_email" data-target-activation="click" data-target="news">
          <div>
            <h2>News 3</h2><h3>24</h3>
          </div>
        </li>

             <li class="tile lower-boxes icon_email" style="width:23.6% !important" data-target-activation="click" data-target="news">
          <div>
            <h2>News 4</h2><h3>24</h3>
          </div>
        </li>

The code below will grab the last 4 posts from my blog. 下面的代码将从我的博客中获取最后4个帖子。 But the problem is how do i get the datalist to output the values so they show up in the section of each li ? 但问题是我如何让数据列表输出值,以便它们显示在每个li的部分?

    <form id="form1" runat="server">
    <div>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://www.website.co.uk/blog/syndication.axd"
            XPath="rss/channel/item [position()<=10]"></asp:XmlDataSource>

    </div>
        <asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1" BackColor="White" BorderColor="#404040" BorderStyle="none" GridLines="Vertical">
            <ItemTemplate>
                <a href="<%#XPath("link")%>">
                    <%#XPath("title")%><br />
                </a>
            </ItemTemplate>
            <AlternatingItemStyle BackColor="CadetBlue" />
            <ItemStyle BackColor="transparent" ForeColor="transparent" />
            <HeaderStyle BackColor="#804040" ForeColor="White" Font-Bold="true" />
        </asp:DataList>
    </form>

For getting plain HTML structure , asp:repeater is most preferable. 为了获得简单的HTML结构,asp:repeater是最优选的。 in repeater what you place in ItemTemplate is coming as output without applying other table or css. 在转发器中,您放置在ItemTemplate中的内容将作为输出而不应用其他表或CSS。

below use repeater for same purpose. 以下使用中继器用于相同目的。

    <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://www.website.co.uk/blog/syndication.axd"
    XPath="rss/channel/item [position()<=10]"></asp:XmlDataSource>
<asp:Repeater ID="rptNews" runat="server" DataSourceID="XmlDataSource1">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <ItemTemplate>
        <li class="tile lower-boxes icon_email" data-target-activation="click" data-target="news">
            <div>
                <h2>
                    <a href="<%#XPath("link")%>">
                        <%#XPath("title")%><br />
                    </a>
                </h2>
                <h3>
                    <%#XPath("description")%></h3>
            </div>
        </li>
    </ItemTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
    </asp:Repeater>

Hope this will help you. 希望这会帮助你。

The code below will grab the last 4 posts from my blog. 下面的代码将从我的博客中获取最后4个帖子。 But the problem is how do i get the datalist to output the values so they show up in the section of each li ? 但问题是我如何让数据列表输出值,以便它们显示在每个li的部分?

If you want to do that, you need to output the <li> elements themselves from the Datalist. 如果你想这样做,你需要从Datalist输出<li>元素。

Something like: 就像是:

<asp:DataList ID="DataList1" runat="server" DataSourceID="XmlDataSource1" BackColor="White" BorderColor="#404040" BorderStyle="none" GridLines="Vertical">
            <ItemTemplate>
                <li> <!-- added li-->
                   <a href="<%#XPath("link")%>">
                      <%#XPath("title")%><br />
                   </a>
                </li>
            </ItemTemplate>
            <AlternatingItemStyle BackColor="CadetBlue" />
            <ItemStyle BackColor="transparent" ForeColor="transparent" />
            <HeaderStyle BackColor="#804040" ForeColor="White" Font-Bold="true" />
        </asp:DataList>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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