JQuery - Checking for gridview pager table row
I have implemented a datasource bound gridview on my aspx page and have added the following jquery to implement several changes when the user hovers over a row. The problem is the jquery also comes into play when you hover over the bottom pager row e.g to change the grid page etc. I had it working with following besides in the case when there isn't a pager row on screen. I've also tried looking for the 'gridheader' class, counting rows etc but none of them seem to do the job.
function PageLoaddCallback(sender, args) {
$("*[id$='gridResults'] tr:not(tr:last-child)").unbind();
$("*[id$='gridResults'] tr:not(tr:last-child)").filter(function () {
return $('td', this).length && !$('table', this).length
}).hover(
function () {
var totalRows = $("#<%=gridResults.ClientID %> tr").length;
m_bgcolour = $(this).css("background-color");
var _img = $(this).find("*[id$='hdnField']").val();
var _name = $(this).find("*[id$='hdnName']").val();
if ((_img == null) || (_img == "")) {
var src = "../../Images/Resources/NoSignature.jpg";
_name = "Unkno开发者_如何学运维wn";
}
else {
var src = "GetImage.axd?id=" + _img;
}
$("#largeImg").attr("src", src);
$(this).css({ background: "#c4ffc4" });
$("#lbl").html(_name);
},
function () {
var src = "../../Images/Resources/sample.jpg";
$("#largeImg").attr("src", src);
$(this).css({ background: m_bgcolour });
$("#lbl").html("Sample");
}
);
}
});
Any help would would be appreciated!
Thanks
You can put a special CssClass on the pager rows like so:
<asp:GridView ...>
<PagerStyle cssClass="pagerRow" />
</asp:GridView>
You should then be able to use that to filter out the rows.
Thanks for the help.. couldn't get your suggestion to work so added a css class to the data rows and changed selector to find the class:
<asp:GridView ID="gridResults" runat="server" AutoGenerateColumns="false" RowStyle-CssClass="dataRow">
$("*[id$='gridResults']").find(".dataRow")
精彩评论