列表视图行颜色更改 [英] listview row color changing

查看:79
本文介绍了列表视图行颜色更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用过

onmouseDown="this.style.backgroundColor='#FFCCCC'"


在列表视图项目模板中单击时将颜色设置为行.
单击新行时,我想更改上一行的颜色.


to set color to row on click in listview item template.
I want to change the color of previous row when new row is clicked.
How this can be achieved?

推荐答案

我为您提供了一种方法来实现您的目标,这是您需要独自旅行的其余里程碑:)

I have given you one approach to reach your goal the rest of milestone you need to travel alone :)

<script>
        function changePrevRowColor(elem) {
            //document.getElementById(elem).style.backgroundColor= "white";
            var lastIndex = elem.lastIndexOf("_");
            var lastsubstringIndex = (elem.substring(lastIndex + 1, elem.length)) - 1;
            if (lastsubstringIndex < 0) {lastsubstringIndex = 0; }

            document.getElementById(elem.substring(0, lastIndex) + "_" + lastsubstringIndex).style.backgroundColor = '#FFCCCC';

        }

    </script>



LISTVIEW:



LISTVIEW:

<asp:ListView ID="lstTest" runat="server" ClientIDMode="Predictable" >
            <ItemTemplate>
                <asp:Label ID="lblRowId" runat="server" Text='<%#Bind("col1") %>' onclick="javascript:(changePrevRowColor(this.id));"></asp:Label>
            </ItemTemplate>
        </asp:ListView>


这篇关于列表视图行颜色更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆