Using ASP.net and c#
using visual studio 2010
Hi all, I hope some one can help me. Basically I have a page that has a grid view that has a link button in one of the columns. What I’m trying to do is; user clicks the link and the PDF file it refers to is loaded in a new page using the site.master. Below is the code I currently have.
Starting page
SelectCommand="SELECT * FROM [Guides] WHERE (([Display] = ?) AND ([Media_Document] = ?))">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="true" Name="Display"
QueryStringField="checkbox" Type="Boolean" />
<asp:QueryStringParameter DefaultValue="Document" Name="Media_Document"
QueryStringField="Media_Document" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server">
</asp:ObjectDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ID" CssClass="mGrid" RowStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
DataSourceID="AccessDataSource1" Width="225px" style="text-align:left"
GridLines="None" >
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:BoundField DataField="Guide" HeaderText="Guide" SortExpression="Guide" />
<asp:HyperLinkField DataNavigateUrlFields="File_location"
DataNavigateUrlFormatString="Guides.aspx?File_location={0}"
Target="content" Text="Link" />
</Columns>
<RowStyle CssClass="pgr"></RowStyle>
</asp:GridView>
</div>
This code generates the link correctly which is Guides.aspx?File_location=blahblahblah.pdf
Destination page
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<object width="800" height="800" data="File_Location"></object>
</asp:Content>
This dose not work because the variable File_location is not recognized which makes sense. I could get the location using c# in the code behind but how do I then display that in the page?
Any Ideas?
Code Behind
public partial class Guides : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string Location = Request.QueryString.ToString();
File_location(Location);
}
public void File_location(string location)
{
string File_Location = location.Substring(location.IndexOf('=') + 1);
}
}
One way would be to have a public property on the code behind page called File_Location and then you would refer to it like this:
Set the value in Page_load.
create a property in the code-behind like this: