Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

in the below code, there is a image present on second column,if i click on second column i wan to read the data present in first column.

suppose i have 10 rows, if user click on 5 row icon, then i want to read all the details associated with 5th row.

    <table class="tableStyle" id="Table1">
        <thead>
              <tr>
                  <th id="Th1" style="background: none repeat-x scroll center top #027DBA;border-left: 1px solid #525252;width:15px;font-weight:bold">
                      <div>Request ID</div>
                  </th>
                  <th id="Th2" style="background: none repeat-x scroll center top #027DBA;border-left: 1px solid #525252;width:15px;font-weight:bold">Request Name
                  </th>
              </tr>
        </thead>
    <%
        for (int i = 0; i < ViewData.Model.Details.Count; i++)
        {
            //String id = i.ToString();

     %>

               <tr>
                   <td headers="Th1" style="background-color:#EFF3FB;border: 1px solid #C1C1C1;color: #000000; text-align:center"><%= ViewData.Model.Details.ElementAt(i).ID%>
                   </td>
                   <td headers="Th2" style="background-color:#EFF3FB;border: 1px solid #C1C1C1;color: #000000; text-align:center">
                        <a href="#"><img style="border:0;" src="/Content/Images/Icon.png" alt="Name" width="20" height="20" /></a>
                   </td>
               </tr>
        <%} 
    %>
</table>
share|improve this question
add comment

1 Answer

Using jQuery, you can attach a click handler on the anchor tag and locate the data by navigating to its parent's previous sibling...

$("a").on("click", function (e) {
    var data = $(this).parent().prev().text();
    alert(data);
    e.preventDefault();
});

JsFiddle

share|improve this answer
    
Thanks, but i have one doubt, i dont have js file in my project, i m trying to achieve everything in aspx page itself. how can i add this inside aspx. thanks for your help. –  Naruto Apr 23 at 5:28
    
Thank you, i m able to achieve now. what you have told. But i have one question, prev() will always give me 1st column data if i click on 2nd, Suppose i have 10 columns, and clicked on 5th column and if i want 1st column data, then how to achieve the same? –  Naruto Apr 23 at 6:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.