3

i am trying to loop through a gridview using jquery, the code i am using is

$('#<%=gridview1.clientid%> tbody tr').not(':first,:last')
  .each(function(){
    gridrows ++;
  });

i would like to eliminate the first and last rows which are obviously the header and footer , i tried this code but seems that it is not working, it is returning the count of gridview rows. any ideas.

2
  • Are you using some kind of plugin for gridrows++ or its just a pseudo-code for some underlying logic...... Commented Oct 18, 2012 at 5:39
  • wow a comment after almost 1 year and 10 months, any way it was pseudocode and i was able to solve it using the link in answer Commented Oct 18, 2012 at 10:32

2 Answers 2

1

Two possible things to consider:

(1) Try to avoid mixing your server code in your jquery. Just use the gridview's ID property $('#myGridView') instead of getting it through the brackets. (Maybe you weren't trying to do that, though.)

(2) Have a read of Rick Strahl's post on this topic. http://www.west-wind.com/weblog/posts/822827.aspx

I believe you'll find it covers the problem you're encountering now.

Sign up to request clarification or add additional context in comments.

1 Comment

that article is a very useful one. thanks for the pointer,@adam kiss sorry i missed the link in mg's answer so now i can add thead to gridview.
0

If you're using <tbody>, why not use <thead>for header and <tfoot> for footer?

<table>
  <thead><tr>..</tr></thead>
  <tbody><tr>..</tr></tbody>
  <tfoot><tr>..</tr></tfoot>
</table>

?

Then you can lose the .not() part. Also, are you sure that that ASP.net code returns existing id? :)

1 Comment

i belive gridview will not generate thead so i have to live with tbody,

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.