倘使你曾看过那篇,http://www.cnblogs.com/insus/articles/1411057.html ,它是在GridView控件中示范,不过它的点子在Repeater控件是力不从心复制的。
由于看到论坛上有网友问及,花上一点点时光做了Repeater控件的言传身教。首先看望效果(动画为止,尝试刷新网页):

2018正版葡京赌侠诗 1

 

为了能在Repeater控件上贯彻onmouseover和onmouseout样式,Insus.NET想如若控到表的行即可,在Repeater控件的OnItemCreated事件中去落成,须求各自写好ItemTemplate模版与AlternatingItemTemplate模版,此外还留意的地方,就是把tr转为web控件,那样幸亏cs好找到。

.aspx(部分):

2018正版葡京赌侠诗 22018正版葡京赌侠诗 3View Code

 <asp:Repeater ID=”Repeater1″ runat=”server” OnItemCreated=”Repeater1_ItemCreated”>
            <HeaderTemplate>
                <table border=”1″ cellpadding=”3″ cellspacing=”0″>
                    <tr>
                        <td>
                            MediaTypeId
                        </td>
                        <td>
                            TypeName
                        </td>
                        <td>
                            Description
                        </td>
                        <td>
                            IsActive
                        </td>
                        <td>
                            CreateDate
                        </td>
                    </tr>
            </HeaderTemplate>            
            <ItemTemplate>
                <tr id=”itl” runat=”server”>
                    <td>
                        <%# Eval(“MediaTypeId”) %>
                    </td>
                    <td>
                        <%# Eval(“TypeName”)%>
                    </td>
                    <td>
                        <%# Eval(“Description”)%>
                    </td>
                    <td>
                        <%# Eval(“IsActive”)%>
                    </td>
                    <td>
                        <%# Eval(“CreateDate”)%>
                    </td>
                </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr id=”att” runat=”server”>
                    <td>
                        <%# Eval(“MediaTypeId”) %>
                    </td>
                    <td>
                        <%# Eval(“TypeName”)%>
                    </td>
                    <td>
                        <%# Eval(“Description”)%>
                    </td>
                    <td>
                        <%# Eval(“IsActive”)%>
                    </td>
                    <td>
                        <%# Eval(“CreateDate”)%>
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>

 

.aspx.cs(部分),有好几内需专注的是,首先得到行的BackColor,那样好的Mouse
out时,回复原来的Color:

2018正版葡京赌侠诗 42018正版葡京赌侠诗 5View Code

 protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item)
        {
            if (e.Item.FindControl(“itl”) != null)
            {
                HtmlTableRow htr_itl = (HtmlTableRow)e.Item.FindControl(“itl”);
                ApplyStyle(htr_itl, htr_itl.BgColor);
            }
        }

        if (e.Item.ItemType == ListItemType.AlternatingItem)
        {
            if (e.Item.FindControl(“att”) 2018正版葡京赌侠诗,!= null)
            {
                HtmlTableRow htr_att = (HtmlTableRow)e.Item.FindControl(“att”);
                ApplyStyle(htr_att, htr_att.BgColor);
            }
        }
    }

    private void ApplyStyle(HtmlTableRow htr, string trBackColor)
    {
        string onmouseoverStyle = “this.style.backgroundColor=’Peachpuff'”;
        string onmouseoutStyle = “this.style.backgroundColor=’@BackColor'”;

        htr.Attributes.Add(“onmouseover”, onmouseoverStyle);
        htr.Attributes.Add(“onmouseout”, onmouseoutStyle.Replace(“@BackColor”, trBackColor));

    }

 

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图