The
RowCommand
event fires for
every command event, which includes clicking on the links to the different pages.
You need to specify a
CommandName
on your
LinkButton
, and verify that the event is firing for your command:
<asp:TemplateField HeaderText="Download">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
Text='<%# Eval("Files") %>'
CommandArgument='<%# Eval("Files") %>'
CommandName="DownloadFiles"
onclick="LinkButton1_Click"
/>
</ItemTemplate>
</asp:TemplateField>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DownloadFiles")
{
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "filename=" + e.CommandArgument);
Response.TransmitFile(Server.MapPath("~/Files/") + e.CommandArgument);
Response.End();
}
}