2

I have an ASP.NET GridView (called "ActionsGrid") with several BoundFields as columns. In my JavaScript, I want to look at each selected row (with class name "highlighted") and extract the cell values from particular columns (1, 3, and 4).

Here's my script:

var params = [];

$('#ActionsGrid tr').each(function () {
    if (this.className === 'highlighted') {
        var record_pk = this.children("td:nth-child(1)");
        var obj_name = this.children("td:nth-child(3)");
        var obj_pk = this.children("td:nth-child(4)");
        params.push(record_pk + "," + obj_name + "," + obj_pk + "¬");
    }
});

My variables just return 'undefined'. Am I close?

2 Answers 2

1

You need to set your ClientID on your ActionGrid. This is the ID that is presented to the client and can be used in JavaScript.

If you have this set to "ActionsGrid" then you are close, however your jQuery selector needs to use a "#" to indicate you are selecting on an ID (like css):

$('#ActionsGrid tr').each(function () {

Also instead of selecting every row, and then checking the class on the row, you can make the class part of your selector. I.e. only select the rows with that class:

$('#ActionsGrid tr.highlighted').each(function () {
Sign up to request clarification or add additional context in comments.

5 Comments

Apologies, the missing "#" was a typo. I've amended the question. Is ClientID different from ID on the grid? The ID is "ActionsGrid".
Then the key is probably setting your ClientId on your grid.
In my DOM explorer, the HTML table ID is also "ActionsGrid". Is this what you mean by ClientID?
Yes. If you can see it in the DOM explorer, then you should be able to select it in jQuery. Is "ActionsGrid" the table element in the DOM?
Yes. Perhaps the problem is with setting the variables?
0

After a little experimentation, I found my variables need to be set like so:

var record_pk = $(this).children("td:nth-child(1)").html();
var obj_name = $(this).children("td:nth-child(3)").html();
var obj_pk = $(this).children("td:nth-child(4)").html();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.