This code should work, verified on my local computer.
First add DataKeyNames to your GridView.
<asp:GridView ID="gv_FilesList" runat="server" AutoGenerateColumns="false" onrowcommand="gv_FilesList_RowCommand" DataKeyNames="f_Id"> <Columns> <asp:BoundField DataField="f_Id" Visible="false" HeaderText="File Name" /> </Columns> <Columns> <asp:BoundField DataField="f_Name" HeaderText="File Name" /> </Columns> <Columns> <asp:ButtonField ButtonType="Link" Text="Download" CommandName="DownloadFile" HeaderText="Download" /> </Columns> </asp:GridView>
Then open DataKeys from codebehind.
protected void gv_FilesList_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DownloadFile") {
source share