2013-07-23 114 views
0

我的網頁上有一個gridview,其中一列是「參考號碼」。參考號代表服務器上的pdf文件的名稱。是否有可能將此欄更改爲超鏈接欄,以便當他們單擊行上的參考號時,它將打開PDF?例如,他們點擊ReferenceNumber 123456並打開pdf \ server \ folder \ 123456.pdf。謝謝從gridview鏈接打開PDF文件?

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    CellPadding="4" DataSourceID="SqlDataSource1" 
    ForeColor="#333333" GridLines="None"> 
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
    <Columns> 
     <asp:CommandField ShowSelectButton="True" /> 
     <asp:BoundField DataField="ReferenceNumber" HeaderText="Reference #" 
      SortExpression="ReferenceNumber" /> 
     <asp:BoundField DataField="Teaching_Hospital_Name" HeaderText="Teaching Hospital Name" 
      SortExpression="Teaching_Hospital_Name" /> 
     <asp:BoundField DataField="Date_of_Payment" 
      HeaderText="Date" SortExpression="Date_of_Payment" /> 
     <asp:BoundField DataField="Physician_First_Name" 
      HeaderText="First Name" SortExpression="Physician_First_Name" /> 
     <asp:BoundField DataField="Physician_Last_Name" 
      HeaderText="Last Name" SortExpression="Physician_Last_Name" /> 
     <asp:BoundField DataField="Recipient_Primary_Business_Street_Address_Line_1" 
      HeaderText="Address 1" 
      SortExpression="Recipient_Primary_Business_Street_Address_Line_1" /> 
     <asp:BoundField DataField="Recipient_City" HeaderText="City" 
      SortExpression="Recipient_City" /> 
     <asp:BoundField DataField="Recipient_State" HeaderText="State" 
      SortExpression="Recipient_State" /> 
     <asp:BoundField DataField="Recipient_Zip_Code" HeaderText="Zip" 
      SortExpression="Recipient_Zip_Code" /> 
     <asp:BoundField DataField="Total_Amount_of_Payment" HeaderText="Total_Amount" 
      SortExpression="Total_Amount_of_Payment" /> 
    </Columns> 
    <EditRowStyle BackColor="#999999" /> 
    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> 
    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> 
    <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> 
    <SortedAscendingCellStyle BackColor="#E9E7E2" /> 
    <SortedAscendingHeaderStyle BackColor="#506C8C" /> 
    <SortedDescendingCellStyle BackColor="#FFFDF8" /> 
    <SortedDescendingHeaderStyle BackColor="#6F8DAE" /> 
</asp:GridView> 

回答

0

您需要將Reference Number字段更改爲TemplateField而不是BoundField,這將讓你把一個超鏈接到該字段。

閱讀Using TemplateFields in the GridView Control

從那裏,我會建議使用HttpHandler打造的PDF文件,它傳輸給用戶。這有兩個好處:

  1. 沒有回傳,所以用戶不會在你的網格顯示中失去他們的位置。
  2. 它允許用戶輕鬆查看和/或保存與您的應用程序分開的PDF。