Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi friends,
I have gridview with following columns
1. SrNo(Label)<br />
.<br />
.<br />
.<br />
5. Delete(HyperLink)


When user clicks on the Delete, I want to the get the value of the label SrNo.

I tried following
$(document).ready(function(){
    $('#btnDelete').live('click',function(){
        var value = $(this).siblings('#lblSrNo').text(); 
        alert(value) ;
    });
});



But above code does not wokrs.

Can anyone tell where I'm going worng??

Thanks in advance
Posted

You don't need to use sibling if you already have the id value. Your selector will be just $("#lblSrNo"). You messed up all together.

—SA
 
Share this answer
 
v2
Comments
dhage.prashant01 14-May-13 2:34am    
I have use siblings, to get the label of that row in which the link is clicked
Sergey Alexandrovich Kryukov 14-May-13 2:35am    
What is unclear in my answer? "#" means "id".
—SA
If you rightclick your site and select "view source" you will probably see that your labels id is not "lblSrNo". asp.net generates id's based on where in the control hierarchy they are. So you will have to either make sure asp.net tells your javascript the correct id, or use another jquery selector.
My suggestion is to add a css-class to all your lbl's and use classname instead of id:

JavaScript
$(document).ready(function(){
    $('#btnDelete').live('click',function(){
        var value = $(this).siblings('.YourClassName').text();
        alert(value) ;
    });
});
 
Share this answer
 
Try below code

JavaScript
$(this).closest('tr').find('td #lblSrNo').html();


Sample on fidle http://jsfiddle.net/zqfYp/3/[^]
 
Share this answer
 
Comments
dhage.prashant01 14-May-13 7:11am    
Your code work fine.
But as per Solution 2, i need to use input tag to find the control

$(this).closest('td').find('input').val(1);

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