I am trying to find out which button in a GridView is calling a JavaScript function by figuring out which row it is in. I am using ASP.NET. Here is the necessary code:
The JavaScript function (only the important part):
function get_notes(sender) {
//...
var grid = document.getElementById('<%= PartGrid.ClientID %>');
var r = 1;
for (var i = 1; i < grid.rows.length; ++i) {
if (grid.rows[i].cells[4] == sender) { //the button is in cells[4]
r = i;
}
}
alert(r); //always shows me "1"
//...
}
The button that calls get_notes (it's in PartGrid, column 4, in a template field):
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" Text="Show"
OnClientClick="get_notes(this); return false;" />
I need to find the row for the button that was clicked because I need to use grid.rows[r].cells[0].innerText
for an ActiveXObject SQL query. I know that the ActiveXObject and SQL query stuff works, I have already tested that out with dummy values. What is wrong with this code, and is there a better way to find the row of the button that I clicked?