根据不同列值,改变repeater某行背景色

时间:2022-02-15 14:47:45
一个repeater列表
先绑定

我想repeater的表格某列里面放了个Lable标签
通过标签里面的值,来改变repeater行的背景色

根据列的 不同值,来改变repeater某一行的背景色

请求大虾帮下 这个要怎么写啊;有代码最好

10 个解决方案

#1


class= <%GetClass(Eval("PType").ToString())%>  返回一个样式名字

#2


  <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
            <table width="100%" align="center" border="0">
            <tr>
                <td style="height: 125px">
                    <table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
                        <tbody>
                            <tr>
                                <td width="7%" height="60">
                                <img src="<%#Eval("LogoImage")==null?null:Eval("LogoImage")%>" alt="<%#Eval("Title") %>" width="50" height="50" />
                                    <%--<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("LogoImage") %>' Visible='<%#Eval("LogoImage")==null || Eval("LogoImage")=="" ?false:true %>' Height="50" Width="50" />--%>
                                </td>
                                <td width="68%" bgcolor="#e6eaff">
                                    <a href="<%#Eval("HtmlUrl") %>" target='_blank'><%# Eval("Title") %></a></td>
                                <td width="25%" align="center" bgcolor="#e6eaff">
                                    <strong>
                                        <%#Eval("MemsFee")%></strong></td>
                            </tr>
                            <tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#f4f6ff'" onmouseout="this.bgColor='#FFFFFF'">
                                <td align="center">
                                    <asp:CheckBox ID="CheckBox1" runat="server" /><asp:Label ID="Label22" runat="server"
                                        Text='<%#Eval("Tag")%>' Visible="false"></asp:Label></td>
                                <td>
                                    <%# Eval("Time") %></td>
                                <td align="center">
                                    <%#Eval("MemsFree")%></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr height="30">
            </tr>
            </table>
            </ItemTemplate>
            <AlternatingItemTemplate>
            <table width="100%" align="center" border="0">
            <tr>
                <td style="height: 125px">
                    <table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
                        <tbody>
                            <tr>
                                <td width="7%" height="60">
                                <img src="<%#Eval("LogoImage")==null?null:Eval("LogoImage")%>" alt="<%#Eval("Title") %>" width="50" height="50" />
                                <%--<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("LogoImage") %>' Visible='<%#Eval("LogoImage")==null || Eval("LogoImage")=="" ?false:true %>' Height="50" Width="50" />--%>
                                </td>
                                <td width="68%" bgcolor="#ffe5d2">
                                    <a href="<%#Eval("HtmlUrl") %>" target='_blank'><%# Eval("Title") %></a></td>
                                <td width="25%" align="center" bgcolor="#ffe5d2">
                                    <strong>
                                        <%#Eval("MemsFee")%></strong></td>
                            </tr>
                            <tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#f4f6ff'" onmouseout="this.bgColor='#FFFFFF'">
                                <td align="center">
                                    <asp:CheckBox ID="CheckBox1" runat="server" /><asp:Label ID="Label22" runat="server"
                                        Text='<%#Eval("Tag")%>' Visible="false"></asp:Label></td>
                                <td>
                                    <%# Eval("Time") %></td>
                                <td align="center">
                                    <%#Eval("MemsFree")%></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr height="30">
            </tr>
            </table>
            </AlternatingItemTemplate>
            </asp:Repeater>

#3


<% if()%><%{%> 内容 <%}%>

#4


引用 1 楼 yue547283947 的回复:
class= <%GetClass(Eval("PType").ToString())%> 返回一个样式名字

用这个方法比较好,返回一个string就行,可以定义多个class
public string GetClass(string PType)    //记住这个方法的修饰符必须是public
{

}

#5


2楼的方法应该能行!

#6


就2楼的方法了!

#7


<asp:Repeater ID="rpt" runat="server" >
                    <ItemTemplate>
                       <tr id="row_<%#Eval("id") %>"  style="background-color:<%#Eval("Color") %>" >
                                <td><input name="ckb" type="checkbox" id="che_<%#Eval("id") %>" value="<%#Eval("id") %>"  /></td>
                                <td><input name="txt" type="text" id='Col1_<%#Eval("id") %>'   value="<%#Eval("Color") %>" /></td>

                        </tr>
                    </ItemTemplate>
                    </asp:Repeater>

#8


2楼根本不行

#9


7楼压根编译就报错

#10


 在源里写:<%#Contents(Eval("TrafficDetails"))%>
在.cs文件里写
  //字符串截取
    public string Contents(object info)
    {
        return StringHandler.CusString(info,15);
    }
根据这种思路做试试看

#1


class= <%GetClass(Eval("PType").ToString())%>  返回一个样式名字

#2


  <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
            <table width="100%" align="center" border="0">
            <tr>
                <td style="height: 125px">
                    <table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
                        <tbody>
                            <tr>
                                <td width="7%" height="60">
                                <img src="<%#Eval("LogoImage")==null?null:Eval("LogoImage")%>" alt="<%#Eval("Title") %>" width="50" height="50" />
                                    <%--<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("LogoImage") %>' Visible='<%#Eval("LogoImage")==null || Eval("LogoImage")=="" ?false:true %>' Height="50" Width="50" />--%>
                                </td>
                                <td width="68%" bgcolor="#e6eaff">
                                    <a href="<%#Eval("HtmlUrl") %>" target='_blank'><%# Eval("Title") %></a></td>
                                <td width="25%" align="center" bgcolor="#e6eaff">
                                    <strong>
                                        <%#Eval("MemsFee")%></strong></td>
                            </tr>
                            <tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#f4f6ff'" onmouseout="this.bgColor='#FFFFFF'">
                                <td align="center">
                                    <asp:CheckBox ID="CheckBox1" runat="server" /><asp:Label ID="Label22" runat="server"
                                        Text='<%#Eval("Tag")%>' Visible="false"></asp:Label></td>
                                <td>
                                    <%# Eval("Time") %></td>
                                <td align="center">
                                    <%#Eval("MemsFree")%></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr height="30">
            </tr>
            </table>
            </ItemTemplate>
            <AlternatingItemTemplate>
            <table width="100%" align="center" border="0">
            <tr>
                <td style="height: 125px">
                    <table cellspacing="1" cellpadding="3" width="90%" align="center" border="0">
                        <tbody>
                            <tr>
                                <td width="7%" height="60">
                                <img src="<%#Eval("LogoImage")==null?null:Eval("LogoImage")%>" alt="<%#Eval("Title") %>" width="50" height="50" />
                                <%--<asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("LogoImage") %>' Visible='<%#Eval("LogoImage")==null || Eval("LogoImage")=="" ?false:true %>' Height="50" Width="50" />--%>
                                </td>
                                <td width="68%" bgcolor="#ffe5d2">
                                    <a href="<%#Eval("HtmlUrl") %>" target='_blank'><%# Eval("Title") %></a></td>
                                <td width="25%" align="center" bgcolor="#ffe5d2">
                                    <strong>
                                        <%#Eval("MemsFee")%></strong></td>
                            </tr>
                            <tr bgcolor="#FFFFFF" onmouseover="this.bgColor='#f4f6ff'" onmouseout="this.bgColor='#FFFFFF'">
                                <td align="center">
                                    <asp:CheckBox ID="CheckBox1" runat="server" /><asp:Label ID="Label22" runat="server"
                                        Text='<%#Eval("Tag")%>' Visible="false"></asp:Label></td>
                                <td>
                                    <%# Eval("Time") %></td>
                                <td align="center">
                                    <%#Eval("MemsFree")%></td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
            <tr height="30">
            </tr>
            </table>
            </AlternatingItemTemplate>
            </asp:Repeater>

#3


<% if()%><%{%> 内容 <%}%>

#4


引用 1 楼 yue547283947 的回复:
class= <%GetClass(Eval("PType").ToString())%> 返回一个样式名字

用这个方法比较好,返回一个string就行,可以定义多个class
public string GetClass(string PType)    //记住这个方法的修饰符必须是public
{

}

#5


2楼的方法应该能行!

#6


就2楼的方法了!

#7


<asp:Repeater ID="rpt" runat="server" >
                    <ItemTemplate>
                       <tr id="row_<%#Eval("id") %>"  style="background-color:<%#Eval("Color") %>" >
                                <td><input name="ckb" type="checkbox" id="che_<%#Eval("id") %>" value="<%#Eval("id") %>"  /></td>
                                <td><input name="txt" type="text" id='Col1_<%#Eval("id") %>'   value="<%#Eval("Color") %>" /></td>

                        </tr>
                    </ItemTemplate>
                    </asp:Repeater>

#8


2楼根本不行

#9


7楼压根编译就报错

#10


 在源里写:<%#Contents(Eval("TrafficDetails"))%>
在.cs文件里写
  //字符串截取
    public string Contents(object info)
    {
        return StringHandler.CusString(info,15);
    }
根据这种思路做试试看