gridview獲取選中行索引及當前行數據javascript
一.非直接綁定數據:java
<!--前臺傳值-->
<asp:TemplateField HeaderText="操做"> <ItemTemplate> <asp:LinkButton ID="lbtnDelete" runat="server" CommandName="CustomDelete" CommandArgument="<%# Container.DataItemIndex) %>>" OnClientClick="javascript:return confirm('真的要刪除嗎?');">刪除</asp:LinkButton> <asp:LinkButton ID="lbtnEdit" runat="server" CommandName="CustomUpdate" CommandArgument="<%# Container.DataItemIndex %>">編輯</asp:LinkButton> </ItemTemplate> </asp:TemplateField>
//後臺獲取 int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView1.Rows[index];
二.綁定數據:spa
<!--前臺傳值-->
<asp:TemplateField> <ItemTemplate> <asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="tt">刪除</asp:LinkButton> </ItemTemplate> </asp:TemplateField>
//後臺獲取Id值 string id = e.CommandArgument.ToString();