现在需要实现 如果Repeater查出的数据行数大于8条就加上  margin-right:16px 的样式 ,本来用js可以实现,但是在Repeater外有一个定时刷新的UpdatePanel控件,这个控件不可去掉,,当局部刷新后就不会加载js啦, 所以现在我想在后台Repeater绑定的时候加上这个样式, 但是找不到style属性 求解 ,,求大神赐教! 

解决方案 »

  1.   

    <% if (this.rpList.Items.Count == 0){ %> ..... <%} %>
      

  2.   

    你可以改成...Count > 8
      

  3.   

    用.FindControl()找到控件,然后给控件加样式
      

  4.   


    但是找到了也没有属性是可以加这个样式的找到控件后设置style撒
      

  5.   


    有点不懂,, 这后面的省略号里怎么写
    这是前台的,
    是前台,因为楼主这个需求压根没必要后台去处理,前台耦合标签直接搞定就over了
      

  6.   


    但是找到了也没有属性是可以加这个样式的找到控件后设置style撒
    o(︶︿︶)o  不会用, 能给出代码吗?  
      

  7.   


    但是找到了也没有属性是可以加这个样式的找到控件后设置style撒
    o(︶︿︶)o  不会用, 能给出代码吗?  不用repeater好多年,把你写的发给我,我看看
      

  8.   


    下班了...sorry不好意思, 刚有事去了
      

  9.   

     DataTable dt = new DataTable();
                dt.Columns.Add("customid");
                for (int i = 0; i < 10; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["customid"] = i.ToString();
                    dt.Rows.Add(dr);
                }
                this.rptData.DataSource = dt;
                this.rptData.DataBind();
    <style type="text/css">
            *{font-family:Arial; font-size:14px;}
            .li_red{ color:#f00;}
        </style><form id="form1" runat="server">
        <div style=" width:900px; margin:0 auto;">     
            <asp:Repeater runat="server" ID="rptData">
                <HeaderTemplate><ul></HeaderTemplate>
                <ItemTemplate>
                    <li class=<%#(this.rptData.Items.Count > 8)? "\"li_red\"":"\"\""%>><%# Eval("customid") %></li>
                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
            </asp:Repeater>
        </div>
        </form>
      

  10.   

    或者
     public int rptCount = 10;
            protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("customid");
                for (int i = 0; i < 10; i++)
                {
                    DataRow dr = dt.NewRow();
                    dr["customid"] = i.ToString();
                    dt.Rows.Add(dr);
                }
                this.rptData.DataSource = dt;
                this.rptData.DataBind();
    ..... <div style=" width:900px; margin:0 auto;">     
            <asp:Repeater runat="server" ID="rptData">
                <HeaderTemplate><ul></HeaderTemplate>
                <ItemTemplate>
                    <%--<li class=<%#(this.rptData.Items.Count > 8)? "\"li_red\"":"\"\""%>><%# Eval("customid") %></li>--%>
                    <li><%# Eval("customid") %></li>
                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
            </asp:Repeater>
        </div>
        </form>
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                var cc = '<%=rptCount %>';
                if (parseInt(cc) > 8) {
                    $("ul li").addClass("li_red");
                }
            })
        </script>
      

  11.   

    like this?
    http://www.cnblogs.com/insus/articles/2060705.html
      

  12.   

    在你博客里看到UpdatePanel ,, 想请教你一个问题,一个页面怎么同时使用两个UpdatePanel ,而且这两个的定时不一样,,我前面做了设置了两个定时, 但是后面一个的定时没效果。UpdatePanel 和ScriptManager有什么关系?
      

  13.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>列表排名</title>
        <style type="text/css">
        *{font-size:12px;list-style:none}
        ul{padding:0 0;margin-left:10px;margin-top:0px}
        li{float:left;width:170px;padding:0 0;margin:0 0;line-height:23px} 
        .em      {width:16px;height:15px;background:url('Images/split_v3.1.png') no-repeat -207px -127px;float:left;text-align:center;line-height:15px;font-family:Arial;color:#fff;font-size:10px;margin-right:9px;_display:inline;margin-top:2px}
        .emTop3 {width:16px;height:15px;background:url('Images/split_v3.1.png') no-repeat -207px -100px;float:left;text-align:center;line-height:15px;font-family:Arial;color:#fff;font-size:10px;margin-right:9px;_display:inline;margin-top:2px;}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
         
         <fieldset style="width:180px">
            <legend>
                <fieldset>考试排行榜</fieldset>
            </legend>
             <ul>
             <asp:Repeater runat="server" ID="p1">
                 <ItemTemplate>
                    <li><span class='<%#Container.ItemIndex<3?"emTop3":"em" %>'><%#Container.ItemIndex+1 %></span> <%#Eval("name")%></li>
                 </ItemTemplate>
             </asp:Repeater>
              </ul>
         </fieldset>
        </form>
    </body>
    </html>
      

  14.   


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>列表排名</title>
        <style type="text/css">
        *{font-size:12px;list-style:none}
        ul{padding:0 0;margin-left:10px;margin-top:0px}
        li{float:left;width:170px;padding:0 0;margin:0 0;line-height:23px} 
        .em      {width:16px;height:15px;background:url('Images/split_v3.1.png') no-repeat -207px -127px;float:left;text-align:center;line-height:15px;font-family:Arial;color:#fff;font-size:10px;margin-right:9px;_display:inline;margin-top:2px}
        .emTop3 {width:16px;height:15px;background:url('Images/split_v3.1.png') no-repeat -207px -100px;float:left;text-align:center;line-height:15px;font-family:Arial;color:#fff;font-size:10px;margin-right:9px;_display:inline;margin-top:2px;}
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
         
         <fieldset style="width:180px">
            <legend>
                <fieldset>考试排行榜</fieldset>
            </legend>
             <ul>
             <asp:Repeater runat="server" ID="p1">
                 <ItemTemplate>
                    <li><span class='<%#Container.ItemIndex<3?"emTop3":"em" %>'><%#Container.ItemIndex+1 %></span> <%#Eval("name")%></li>
                 </ItemTemplate>
             </asp:Repeater>
              </ul>
         </fieldset>
        </form>
    </body>
    </html>
      

  15.   

    按照你的编程思路,你就不应该用那么低级的Repeater,而应该是什么最合适用什么。例如DataList、GridView之类的。对你来说,控件Repeater没有什么内涵可以帮你提高开发速度,因此你找不到Style属性。
      

  16.   

    其实某些人、使用Repeater的人,完全可以非常同意地在自己的代码中用一、两分钟时间解决这个问题。但是你根本不知道在提问题时必须告诉别人什么信息才能求助,足以证明你不是这类人。那么我最直接的建议,就是你应该使用对你更加合适的控件来开发,而不是Repeater。
      

  17.   

    如果Repeater查出的数据行数大于8条就加上  margin-right:16px 的样式 ,本来用js可以实现,但是在Repeater外有一个定时刷新的UpdatePanel控件,这个控件不可去掉,,当局部刷新后就不会加载js啦, 所以现在我想在后台Repeater绑定的时候加上这个样式, 但是找不到style属性 求解 ,,求大神赐教!
      

  18.   

    Refer:
    http://www.cnblogs.com/insus/archive/2013/05/19/3086475.html