Thursday, March 28, 2013

jQuery : How to find row and column index of a GridView Cell

on the hover function of (" tr td") :


            var colindex = $(this).closest("tr td").prevAll("tr td").length;
            var rowindex = $(this).closest("tr").prevAll("tr").length;


Here is the complete function :


 $(document).ready(function() {
            $("#<%=GridView1.ClientID%> tr td").hover(
        function()  {
            var colindex = $(this).closest("tr td").prevAll("tr td").length;
            var rowindex = $(this).closest("tr").prevAll("tr").length;
/* mlabel is an asp.net label on which we will display col and row index of current GridView cell
            $(document).find("#<%=mlabel.ClientID%>").text(colindex + ' ' + rowindex);
        },
       
        function() { $(this).css("background-color", "blue"); }
       
        );
        });



$("#<%=GridView1.ClientID%> tr td") indicates one GridView cell.

No comments:

Post a Comment

How to check local and global angular versions

 Use the command ng version (or ng v ) to find the version of Angular CLI in the current folder. Run it outside of the Angular project, to f...