开发者

How to get row index of a gridview row clicked by a user on it by javascript?

开发者 https://www.devze.com 2022-12-17 22:37 出处:网络
How to get row index of a gridview row clicked by a user on it开发者_开发百科 by javascript ?Here is a little sample:

How to get row index of a gridview row clicked by a user on it开发者_开发百科 by javascript ?


Here is a little sample:

<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>


Give every row an unique id with the same suffix.

As example:

<table>
    <tbody>
        <tr id="row_1">
            <td>
                <input  onpasteventorwhatever="related_function(event,1)">
                </input>
            </td>
        </tr>
    </tbody>
</table>


I believe the answer to this older question will provide the answer you need.


<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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号