2010-01-26 61 views

回答

2

這裏是一個小例子:

<asp:GridView ID="GridView1" runat="server"> 
    <Columns> 
     <asp:TemplateField> 
      <ItemTemplate> 
       <input type="button" value="getIndex" onclick="getIndex(<%# Container.DataItemIndex %>);" /> 
      </ItemTemplate> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

<script type="text/javascript"> 
    function getIndex(index) { 
     alert(index); 
    } 
</script> 
+0

喜怎樣到達這裏的行ID: 的'/> – 2014-01-30 10:57:34

1

爲每行提供一個具有相同後綴的唯一id

作爲例子:

<table> 
    <tbody> 
     <tr id="row_1"> 
      <td> 
       <input onpasteventorwhatever="related_function(event,1)"> 
       </input> 
      </td> 
     </tr> 
    </tbody> 
</table> 
0
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" 
      onclick="EditCell(event);".............. 


<script type="text/javascript"> 
     function EditCell(e) { 
      var rowIndex = e.srcElement.parentElement.sectionRowIndex; 
      var cell = document.getElementById("GridView1").rows[rowIndex].cells[e.srcElement.cellIndex].innerText; 
      alert(cell); 
     } 
    </script> 
+1

爲了讓您的答案更有用,請提供一些見解或您的代碼上下文的解釋。有關幫助,請參閱StackOverflow上的[如何編寫一個合適的答案](http://stackoverflow.com/help/how-to-answer)。 – jacefarm 2016-12-02 18:08:49