If you want to display content in a new popup.aspx page with the filename as a query parameter, you can follow this example below:
<asp:GridView ID="FilterGrid" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField HeaderText="FileName" >
<ItemTemplate>
<asp:HyperLink ID="ActionHyperLink" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# Eval("FileName","~/FilePopUp.aspx?filename={0}") %>' Target="_blank" />
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# String.Format("filepopup.aspx?filename={0}", Eval("filename")) %>' onclick="javascript:w= window.open(this.href,'DownloadFile','left=20,top=20,width=500,height=500,toolbar=0,resizable=0');return false;"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The Page_Load method for the popup page:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["filename"] != null)
{
//Retrieve content from the database
byte[] fileContent = ....;
Response.Clear();
string doctype = ...;
if (doctype == ".doc")
{
Response.ContentType = "application/msword";
}
else if (doctype == ".pdf")
{
Response.ContentType = "application/pdf";
}
else if (doctype == ".xls")
{
Response.ContentType = "application/vnd.ms-excel";
}
else if (doctype == ".xlsx")
{
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
}
Response.BinaryWrite(fileContent);
}
}