gridview獲取選中行索引及當前行數據


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();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM