1

Is there anyway to loop through a nested gridview? This is the javascript I have so far, I don't think I'm far off a solution:

$(document).ready(function() {
    $("#<%=gvAdmin.ClientID %> tr").each(function() {
        $(this).find(".gvSubMain tr").each(function() {
            var hdnDate = $(this).find(".Date").val();
            //Do Stuff
        });
    });
});

The two gridviews are; a major gridview called gvAdmin, and the nested gridview called gvSubAdmin. I have looked at this problem for quite a while and see variations such as:

$(document).ready(function() {
    $("#<%=gvAdmin.ClientID %> tr").each(function() {
        $(this).find(".gvSubMain > tr").each(function() {
            var hdnDate = $(this).find(".Date").val();
            //Do Stuff
        });
    });
});

And another variation:

$(document).ready(function() {
    $("#<%=gvAdmin.ClientID %> tr").each(function() {
        $(this).find(".gvSubMain").find("tr").each(function() {
            var hdnDate = $(this).find(".Date").val();
            //Do Stuff
        });
    });
});

But none of these work, is it a small syntax problem that I'm struggling with or is it something in my logic? Do I need to used the .find(".gvSubMain") or can I call the gridview some other way?

Thanks,

Firstcape

2
  • Have you put this code in document.ready? Commented Mar 22, 2013 at 10:49
  • Sorry yes, I should have stated that, the jQuery here is all wrapped in a $(document).ready(function() { Commented Mar 22, 2013 at 10:51

1 Answer 1

2

Try this:

$(document).ready(function () {
    $("#<%=gvAdmin.ClientID %> > tbody > tr").each(function () {
        $(this).find(".gvSubMain > tbody > tr").each(function () {
            var hdnDate = $(this).find(".Date").val();
            //Do Stuff
        });
    });
});
Sign up to request clarification or add additional context in comments.

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.