Error in taking value from gridview by jquery

Posted by Klbaiju under jQuery on 3/20/2014 | Points: 10 | Views : 3362 | Status : [Member] | Replies : 2
Hi all,

I want to add a class name to a gridview cell take the value from the cell;

following is my code

$("#GridView1 tr td").filter(":not(td:first-child)").each(function () {
var colindex = $(this).closest("tr td").prevAll("tr td").length;
var headertext = $("table[id*=GridView1] th").eq(colindex).text();
var cellText = $(this).text();
if ($.trim(cellText) == '')
{
$(this).css('background-color', 'LightGreen');

}
else
{
var name = $(this).text();
if (headertext == 2500) {
$(this).addClass('a')
}
if (headertext == 2501) {
$(this).addClass('b')
}

var atime = $(this).find('.a').text();
alert(name);

}

});

the problem is class name is added to gridview cell according to condition

but iam not getting the value according to this code

var atime = $(this).find('.a').text();
alert(name);

alert displaying null value

but gridview rendered like this

<td class="a">09:15</td>

<td class="b">08:55</td>

means class value adding correctly.

below is sample out put

workingday 2500 2501 2502 2503 2504 2505 2506 2507
01 Jan 2014 09:15 08:55 NULL NULL NULL NULL NULL NULL
02 Jan 2014 10:15 NULL NULL NULL NULL NULL NULL NULL

how to solve this

Regards

Baiju




Responses

Posted by: Sumit08 on: 3/24/2014 [Member] Starter | Points: 25

Up
0
Down
just put debugger and check what you get into this and then check what is inside the this.@klbaiju

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A2H on: 3/25/2014 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,
You need to slightly change the code from this
var atime = $(this).find('.a').text(); 
alert(name);

to
 var atime = $(this).closest("td").closest("tr").find(".a").text();
alert(atime);


Thanks,
A2H
My Blog

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response