1

Visual Studio 2010 を使用して ASP.net と c# を使用する

こんにちは、誰かが私を助けてくれることを願っています。基本的に、列の1つにリンクボタンがあるグリッドビューを持つページがあります。私がやろうとしていることは次のとおりです。ユーザーがリンクをクリックすると、参照先の PDF ファイルが site.master を使用して新しいページに読み込まれます。以下は私が現在持っているコードです。

開始ページ

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>

このコードはリンクを正しく生成します。 Guides.aspx?File_location=blahblahblah.pdf

リンク先ページ

<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>     

意味のある変数File_locationが認識されないため、これは機能しません。コードビハインドでc#を使用して場所を取得できましたが、それをページに表示するにはどうすればよいですか?

何か案は?

コードビハインド

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);
    }
}
4

1 に答える 1

1

1 つの方法は、コード ビハインド ページに File_Location というパブリック プロパティを設定し、次のように参照することです。

<object width="800" height="800" data="<%=File_Location%>"></object>

Page_load に値を設定します。

次のようにコード ビハインドでプロパティを作成します。

public string File_location()
{
    get
    {
        string location = Request.QueryString;
        return = location.Substring(location.IndexOf('=') + 1);
    }
}
于 2012-06-21T05:25:58.463 に答える