locked
Cannot find current Repeater row from linkbutton onclientclick event RRS feed

  • Question

  • User1909155429 posted

     I am trying to display the label in the current row when i click the link button. what happens is it displays the Labelbody in the top row no matter which row i select?

    <asp:LinkButton ID="LinkButton1"   OnClientClick="javascript:document.getElementById('body').classList.toggle('hide');return false"    runat="server"><%#DataBinder.Eval(Container,"DataItem.Subject")%></asp:LinkButton> 

       
             <p id="body" class="hide"  >

             <asp:Label ID="LabelBody" runat="server"  Text='<%#DataBinder.Eval(Container,"DataItem.Body")%>'></asp:Label>
             </p>
       

    Thursday, December 10, 2020 10:09 PM

Answers

All replies

  • User475983607 posted

    You are over complicating the code code.  Use a standard HTML link since you are not posting back.  Use the JavaScript parentElement to get to the row.

    https://www.w3schools.com/jsref/prop_node_parentelement.asp

    From there you can get the to the p.body.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 10, 2020 10:30 PM
  • User1909155429 posted

    I am attempting to get the child element.not the parent.i dont see a command for this?

    Tuesday, December 15, 2020 1:50 PM
  • User475983607 posted

    I am attempting to get the child element.not the parent.i dont see a command for this?

    Your response makes little sense.  I assumed the code you shared is the child row.  You need to move up one level (parent) to get to the HTML container (<td>).  Then you you can find the sibling element.   

    The code you shared could be incomplete.  We have no way to verify but it seems like you might not understand HTML and selectors.  Anyway, make an effort to share code the community can run and reproduces this issue.  

    Tuesday, December 15, 2020 2:14 PM