locked
Repeater Loop using jquery RRS feed

  • Question

  • User1126057398 posted

    How can one loop through repeater using jquery?

    I had got a repeater, which contains 2 rows. In 1st row there is hidden field, I have to check it's value and depending on it's value class are applied on second row's cell.

    Something like below.

    function checkQuestionsAnsweredByUser() {

    alert($('#CustomerAns').val()); var row = $('#CustomerAns').closest('tr');
    var nextrow = row.next('tr'); //contains answer
    if ($('#CustomerAns').val().trim() != '') //If Consumer had answered questions
    {
    //alert(nextrow.find('[id$=RES_B]').attr('title')); Label ToolTip
    if ($('#CustomerAns').val().trim() == 'RES_B') {
    // alert(nextrow.find('[id$=RES_B]').text()); //contains ans
    var tooltip = nextrow.find('[id$=RES_B]').attr('title');
    if (tooltip.trim() == 'Happy') {
    nextrow.find('[id$=RES_B]').addClass('bgClrHappy');
    //Add class for Happy and Remove class for Sad,Indifferent
    row.find(".myimg").addClass('imgpichappy').removeClass('test');
    }
    }
    }
    else
    alert('v');
    //else if ($('#CustomerAns').val().trim() == '2')
    // row.find(".btncolor").addClass('bgClrHappy');
    }

    Wednesday, April 17, 2019 12:43 PM

Answers

  • User1126057398 posted

    Done it like below:

    In 1st row,  <asp:HiddenField ID="CustomerAns" Value='<%#Eval("ResponseAns") %>' runat="server" ClientIDMode="Static" /> 

    $("[id *=CustomerAns]").each(function (e) {
    var row = $(this).closest('tr');
    var custAns =$(this).val();
    var nextrow = row.next('tr'); //contains answer
    if (custAns.trim() != '') //If Consumer had answered questions
    {
    /* First Answer -'RES_A' */
    if (custAns.trim() == 'RES_A') {
    // alert(nextrow.find('[id$=RES_B]').text()); //contains ans
    var tooltip = nextrow.find('[id$=RES_A]').attr('title'); //alert(tooltip);
    // var tooltip = nextrow.find('[id$=RES_B]').attr('title');
    if (tooltip.trim() == 'Happy') {
    nextrow.find('[id$=RES_A]').addClass('bgClrHappy');
    //Add class for Happy and Remove class for Sad,Indifferent
    row.find('.myimg').addClass('imgpichappy').removeClass('test');
    }
    else if (tooltip.trim() == 'Sad') {
    nextrow.find('[id$=RES_A]').addClass('bgClrSad');
    //Add class for Happy and Remove class for Sad,Indifferent
    row.find(".myimg").addClass('imgpicsad').removeClass('test');
    }
    else if (tooltip.trim() == 'Indifferent') {
    nextrow.find('[id$=RES_A]').addClass('bgClrInd');
    //Add class for Happy and Remove class for Sad,Indifferent
    row.find(".myimg").addClass('imgpicind').removeClass('test');
    }
    }

    }

    });

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 18, 2019 5:41 AM