Click here to Skip to main content
15,063,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used
C#
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?
Posted
v2

1 solution

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

XML
<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:

XML
<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>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900