laskydiver
asked on
Gridview Control ASP.net download file using hyperlink from database
I using Gridview control to display some data from SQL database. One of these items is a path to a directory that holds PDF files. Rather than show the path in the Gridview I would like to display a hyperlink that will open or download the PDF file. Any help would be appreciated.
Current Page code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPa ge.master" AutoEventWireup="false" CodeFile="Punch_Grid.aspx. vb" Inherits="Punch_Grid" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head " Runat="Server">
<style type="text/css">
.auto-style24 {
width: 470px;
}
.auto-style25 {
width: 409px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Cont entPlaceHo lder1" Runat="Server">
<p>
<table class="auto-style1">
<tr>
<td class="auto-style25">  ;</td>
<td class="auto-style24">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" Text="Punch List Review"></asp:Label>
</td>
<td> </td>
</tr>
</table>
</p>
<p>
</p>
<p>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False " BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" DataKeyNames="ID" DataSourceID="SqlDataSourc e1" ForeColor="Black" GridLines="Vertical" Width="1291px">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="TagNo" HeaderText="TagNo" SortExpression="TagNo" />
<asp:BoundField DataField="Path" HeaderText="Path"
SortExpression="Path" />
<asp:ButtonField ButtonType="Link" Text="Download" CommandName="Download" HeaderText="Download" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyl e BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderSty le BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BlackRhi noConnecti onString %>" SelectCommand="SELECT * FROM [Punch]"></asp:SqlDataSour ce>
</p>
</asp:Content>
A.JPG
Current Page code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPa
<asp:Content ID="Content1" ContentPlaceHolderID="head
<style type="text/css">
.auto-style24 {
width: 470px;
}
.auto-style25 {
width: 409px;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Cont
<p>
<table class="auto-style1">
<tr>
<td class="auto-style25"> 
<td class="auto-style24">
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large" Text="Punch List Review"></asp:Label>
</td>
<td> </td>
</tr>
</table>
</p>
<p>
</p>
<p>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="TagNo" HeaderText="TagNo" SortExpression="TagNo" />
<asp:BoundField DataField="Path" HeaderText="Path"
SortExpression="Path" />
<asp:ButtonField ButtonType="Link" Text="Download" CommandName="Download" HeaderText="Download" />
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyl
<SortedDescendingCellStyle
<SortedDescendingHeaderSty
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BlackRhi
</p>
</asp:Content>
A.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
File download from GridView rows in ASP.NET
hope this helps.