I have a gridview table that displays at most 25 table rows per page and each row consists of 3 TD element. In the three TDs of each row, the anchor tags href values look something like the following:
href = “primaryresource.aspx?resourceId=78”
href = “secondaryresource.aspx?resourceId=78”
href = “backupresource.aspx?resourceId=78”
I am trying to get the href of the first TD in each table row and use the resourceId in it as the ID for the row (TR tag). The first TD contains the primaryresource id unlike the others in the same row which contain secondary resource ids. I have tried the following but it seems to repeat the same resourceId instead of grabbing the primary resource ID from the first column in each row.
$(function () {
let rows;
let id = '';
let links = $("[id*=GridView1] td a");
rows = $("[id*=GridView1] tr");
let link = '';
for (let i = 0; i < links.length; i++) {
link = $(links[i]).attr("href");
id = link.substring(eval(link.indexOf('=') + 1));
$(rows[i]).attr("id", 'rsc_' + (id));
}
});type or paste code here
Well your selector isnt right. That selects ALL td’s with a link in it. The TD’s you want are those that are the first child of the row…also why are you fuzzy-selecting the table?
links[i] is already a reference to the object, you don’t need to select it again. same with rows[i].