gridview获取选中行索引及当前行数据
一.非直接绑定数据:
<!--前台传值-->
<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];
二.绑定数据:
<!--前台传值-->
<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();