DRAG AND DROP - find values in control

peter liles 556 Reputation points
2022-06-30T23:33:53.867+00:00

I want to get the value of label LabRef and pass to Ajax function for processing. At moment i am retrieving value of hidden field from draggable div inside Repeater control but now need to pass the label value also.

function OnDragStart(e) {

e.dataTransfer.effectAllowed = 'move';  

e.dataTransfer.setData('text', $(this).find('HiddenField[ID*="HiddenField1"]'));  

}
function OnDrop(e) {

$(this).append("<div class='selectedproduct' data-product-name='" + e.dataTransfer.getData('text') + "'>" + e.dataTransfer.getData('text') + "</div>");

    var data = new Array(1);  
    $("#img1 div").each(function (index) {  
        data[index] = "'" + this.innerHTML + "'";  

    });  

    function sendMyAjax(URL_address) {  
        $.ajax({  
            type: 'POST',  
          
            url: URL_address,  
            contentType: "application/json; charset=utf-8",  
            data: '{products:[' + data.join() + ']}',  
            dataType: 'json',  
            success: function (results) { alert(results.d); },  
            error: function () { alert('error'); }  
        }); return false;  
    };  

}

<ItemTemplate>

                                    <tr  class="w3" id="trID" runat="server" >  
                                        
                                        <td>  

                                            <asp:CheckBox ID="chkDeleted" runat="server" Text=""></asp:CheckBox>  
                                        </td>  
                                        <td>  

                                            
                <div draggable="true" id="lnk">  
                                                <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#DataBinder.Eval(Container, "DataItem.InboxID")%>' />  

                                               
            <asp:LinkButton ID="LinkButton1" CommandName="Message"  style="width:400px;white-space: normal;" CommandArgument='<%#DataBinder.Eval(Container, "DataItem.InboxID")%>' Text='<%#DataBinder.Eval(Container, "DataItem.Subject")%>' runat="server"></asp:LinkButton>  
                                                

                                            </div>  


                                        </td>  
                                        <td>  
                                            
                                                <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.Datentime", "{0:g}")%>'></asp:Label>  
                                           

                                        </td>  
                                         
                                        <td>  
                                            <asp:Label ID="LabRef" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.MessageType")%>'></asp:Label>  
                                            
                                        </td>  
                                         
                            
                                    </tr>  


                                </ItemTemplate>
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-07-01T05:57:31.683+00:00

    Hi @peter liles ,
    The code you provided is incomplete.
    From your description, I think you want to get the label value in the Repeater control.
    You can use jquery to find the label value, see the example below.

      var size = $('.nameLabel').length;  
                for (i = 0; i < size; i++) {  
                    var name = $('.nameLabel').eq(i).text();            
                    console.log(name);  
                }              
    

    216785-image.png
    Edit

    <style>  
      div {  
        margin: 0em;  
        padding: 2em;  
      }  
      #source {  
        color: blue;  
        border: 1px solid black;  
      }  
      #target {  
        border: 1px solid black;  
      }  
    </style>  
    

    217324-image.png
    217290-image.png
    217314-12345.gif
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. peter liles 556 Reputation points
    2022-07-01T21:57:00.813+00:00

    var count = $(this).find("div[data-product-name='" + e.dataTransfer.getData('text') + "']").length;

    if (count <= 0) {  
    

    The above code goes first in the ondrop function. i believe it is for counting stored records?

    The code you provided does obtain a value but i need the selected row value not a list of row values. i am trying to retrieve this value and add to the dataTransferSetdata method like the hiddenfield value. Then pass those two values to the webmethod server side using Ajax call.

    Maybe if i place lable inside draggable container that would help? I actually tried but failed to achieve aim.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.