user793468
user793468

Reputation: 4976

capturing cell location for a dynamic HTML Table

Is there a way to identifying a cell location for a dynamic HTML Table in a partial view?

Dynamic Table:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<div>
<table>
        <tr>
            <th>
                Student ID
            </th>
            <th>
                Quarter
            </th>            
            <th>
                Subject
            </th>
            <th>
                Section
            </th>             
</table>
</div>
<div>
<table>
        <% if (Model != null)                    
           foreach (var item in Model) { %>
         <tr>
             <td>
                 Html.Encode(item.StudentID)
             </td>
            <td>
                 Html.Encode(item.Quarter)
            </td>  
            <td>
                 Html.Encode(item.Subject)
            </td>
            <td>
                 Html.Encode(item.Section)
            </td>        
    <%}%>
</table>
</div>

Thanks in advance

Upvotes: 0

Views: 123

Answers (1)

Sergei Zahharenko
Sergei Zahharenko

Reputation: 1524

If i understand correctly?

$('td').click(function(){
    var row = $(this).parent().index();
    var cell = $(this).index();
    $(this).text(row + '/' + cell);
}).trigger('click')

http://jsfiddle.net/2HUtH/

Upvotes: 1

Related Questions