Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<asp:Repeater ID="rptDestroy" runat="server" >
<ItemTemplate>
<tr>
<td><%#Eval("productName") %></td>
<td><%#Eval("ProductId") %></td>
<td><%#Eval("Attid") %></td>
<td><%#Eval("vname") %></td>
<td><%#Eval("PendingQty") %></td>
<td>
<asp:TextBox ID="txtDestroyQty" CssClass="txt" runat="server"></asp:TextBox>
<a href="javascript:Destroy('<%#Eval("vendorId") %>','<%#Eval("ProductId") %>','<%#Eval("Attid") %>')">Destroy</a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>



and my jqery is


function Destroy(vid, Pid, Attid) {
var obj = {};
obj.vid = vid;
obj.pid = Pid;
obj.attid = Attid;
obj.pendingqty = pendingqty;
$.ajax({
type: "POST",
url: "/stocks/Rejection.aspx/DestroyItem",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {

if (data.d == "Y")
window.location.href = '/stocks/rejection.aspx';
else
alert('Not Destroyed');

},
error: function (result) {
alert('went wrong');
}

});
}

What I have tried:

var value = $(this).closest('td').find("input[id*='txtDestroyQty']");
var value = $(this).closest("[id*='rptDestroy']").find("input[id*='txtDestroyQty']");
alert(value);
Posted
Updated 18-May-16 22:29pm

1 solution

try this,
dont use href to call javascript object, you wont be able to get the current object ( Anchor tag) instead you will get the window object.
you will have to use onclick event to pass the current anchor object to the javascript function..
and you have to pass this object to the javascript function,
provide the header td's in the Header template, else the DOM of repeater will not be in a proper manner, It will be difficult to find the elements using Jquery..

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="jquery-1.8.2.js"></script>
    <title></title>
    <script> 
        function Destroy(anchorObj, vid) { 
            var value = $(anchorObj).closest('td').find("input[id*='txtDestroyQty']").val();
            alert(value);

        }
    </script>
   
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:Repeater ID="rptDestroy" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <td></td> <td></td> <td></td> <td></td><td></td><td></td>
                        </tr>
                    
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td><%#Eval("productName") %></td>
                        <td><%#Eval("ProductId") %></td>
                        <td><%#Eval("Attid") %></td>
                        <td><%#Eval("vname") %></td>
                        <td><%#Eval("PendingQty") %></td>
                        <td>
                            <asp:TextBox ID="txtDestroyQty" CssClass="txt" runat="server"></asp:TextBox>
                            <a href="#" onclick="Javascript:Destroy(this,'<%#Eval("vendorId") %>')">Destroy</a>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

        </div>
    </form>
</body>
</html>
 
Share this answer
 
v2
Comments
kumari567 19-May-16 4:46am    
thank you so much ......I was stuck in this code yesterday....and you solve it in a minute ....brillent..thanku so much
Karthik_Mahalingam 19-May-16 4:48am    
welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900