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

 using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; using System.Xml.XPath; //<table class="common-table medium js-table js-stre...