zoukankan      html  css  js  c++  java
  • 使用repeater,遍历数据,不规则排序,不同的样式之间切换

    如图最下面那副图片的文字说明在图片的右边,而其它图片的文字说明在图片的下方,要实现这种效果,其实只要在HTML部分用样式控制,就可以达到了。

    前台代码:

    先在CSS.CSS样式文件里定义二个更换的样式,

    .class3{ position:absolute; left:310px; top:600px; 280px;}

    .class4{ }

    <div id="main" >
    <ul>
    
        <asp:Repeater ID="datalist" runat="server">
            <ItemTemplate>
                    <li style="float:left;">
                             <div class='<%# (Container.ItemIndex) == 4 ? "class1" : "class2" %>'><img src="<%#Eval("imgUrl") %>" width="280px" height="180px" /></div><br />
    
                            <div  runat="server" class='<%# (Container.ItemIndex) == 4 ? "class3" : "class4" %>'><a href="newsDisplay.aspx?id=<%#Eval("ID") %>"><div style="margin-top:10px; font-size:12px;">
                                <span style="color:#9D6E31; font-size:16px;">><%#Eval("title") %></span><br />
                               <%#getContent(Eval("content").ToString()) %>
                            </div></a></div>
                    </li>
            </ItemTemplate>
        </asp:Repeater>
        </ul>
    </div>
    
    最重要的就是class='<%# (Container.ItemIndex) == 4 ? "class3" : "class4" %>',这句了,这句让数据行索引自己判断是到第几行了,用一个三元运算符判断选择哪个样式。


    后台代码很简单,和普通的绑定一样。

    代码
    1 public partial class index : System.Web.UI.Page
    2 {
    3 aboutus us = new aboutus();
    4 protected void Page_Load(object sender, EventArgs e)
    5 {
    6 bind();
    7 }
    8 protected string getContent(string str)
    9 {
    10 if (str.Length > 80)
    11 {
    12 str = str.Substring(0, 80) + "...";
    13 }
    14 return str;
    15 }
    16 protected void bind()
    17 {
    18 string sql = "select top 5 ID,title,content,imgUrl from main where type='ABOUTUS' order by [order] desc";
    19 this.datalist.DataSource = DbHelperOleDb.Query(sql);
    20 this.datalist.DataBind();
    21 }
    呵呵,很简单的,当时弄这个的时候头都想破了。问了好多人。

  • 相关阅读:
    HDU----(4291)A Short problem(快速矩阵幂)
    HDU----(2157)How many ways??(快速矩阵幂)
    hdu---(2604)Queuing(矩阵快速幂)
    hdu---(5038)Grade(胡搞)
    齐次方程到矩阵(番外篇)
    uva--1339
    hdu----(5023)A Corrupt Mayor's Performance Art(线段树区间更新以及区间查询)
    hdu----(2848)Repository(trie树变形)
    hdu---(1800)Flying to the Mars(trie树)
    hdu----(1075)What Are You Talking About(trie之查找)
  • 原文地址:https://www.cnblogs.com/sheseido/p/1865770.html
Copyright © 2011-2022 走看看