首页 .NET/Web repeater 嵌套table和ul实现改变整行row或li的css字体颜色

repeater 嵌套table和ul实现改变整行row或li的css字体颜色

作者:胡同里的砖头 围观群众:1467 更新于:2013-12-19

table的用法:

<asp:Repeater ID="Repeater1" runat="server" >
    <ItemTemplate>
       <table width="97%" height="25" border="0" align="center" cellpadding="0" cellspacing="0" style="border-bottom:1px #999999 dotted;">
         <tr id="row" runat="server">
           <td width="3%" align="center" class="cheng"> ·</td>
           <td width="97%" class="hei12" align=left>
              <a href="#" title="<%#Eval("titleName")%>" target="_blank">
                <font color='#ff0000'><%#Eval("titleName")%></font>(<%#Eval("AddTime", "{0:MM/dd}")%>) </a></td>
         </tr>
       </table>
    </ItemTemplate>
 </asp:Repeater>

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
      if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
      {
             ((HtmlTableRow)e.Item.FindControl("row")).BgColor= "#FF0000";
      }

 }

ul的用法:

<ul class="ChengGong_List">
    <asp:Repeater ID="Repeater1" runat="server"  onitemdatabound="Repeater1_ItemDataBound">
    <ItemTemplate>
    <li runat="server" id="li">
        <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("P_BuyType") %>' />
        昵称:<%# Eval("P_Author") %>&nbsp;&nbsp;地区:<%# Eval("P_Address") %>li>
    </ItemTemplate>
    </asp:Repeater>
    </ul>

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            HiddenField hid = e.Item.FindControl("HiddenField1") as HiddenField;
            if (Convert.ToInt32(hid.Value) == 1)
                ((HtmlControl)e.Item.FindControl("li")).Style.Add("color","green");
            else
                ((HtmlControl)e.Item.FindControl("li")).Style.Add("color", "blue");
        }
    }

  • 本文标题: repeater 嵌套table和ul实现改变整行row或li的css字体颜色
  • 文章分类:【.NET/Web】
  • 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
留言评论
站点声明:
1、本站【胡同里的砖头】个人博客,借鉴网上一些博客模板,取其各优点模块自行拼装开发,本博客开发纯属个人爱好。
2、所有笔记提供给广大用户交流使用,可转载,可复制,纯个人开发所遇问题锦集记录使用
Copyright © huzlblog.com All Rights Reserved. 备案号:苏ICP备2021056683号-8