简体   繁体   中英

How can I pass the url of a selected image which is included in a listview from one aspx page to another?

I am working on my class project where I created an image gallery using listview. The Designing is below:

<asp:ListView ID="lvPresent" runat="server" DataSourceID="SqlDataSource1">
    <LayoutTemplate>
        <table>
            <tr>
                <td></td>
            </tr>
        </table>
        <asp:PlaceHolder ID="itemPlaceHolder" runat="server"></asp:PlaceHolder>
    </LayoutTemplate>
    <ItemTemplate>
        <td>
            <asp:HyperLink ID="HyperLink1" runat="server">

                <asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />

            </asp:HyperLink>
        </td>
    </ItemTemplate>

</asp:ListView>

How can I send the url of the selected image from one .aspx page to another anothe ?

To send URL to another page you can use QueryString . Modify your HyperLink and add NavigateUrl

NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'

just replace you code:-

<asp:HyperLink ID="HyperLink1" runat="server">

  <asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />

</asp:HyperLink>

with

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#"yourNextPageName.aspx?imgURL="+ Eval("url")%>'>

  <asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />

</asp:HyperLink>

Add image URL as query string ,
NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>' in HyperLink

   <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='yourNextPageName.aspx?imgURL=<%# Eval("url")%>' >

            <asp:Image ID="ImageButton1" runat="server" ImageUrl='<%#Eval("url")%>' Height="200px" Width="250px" />

        </asp:HyperLink>

In destination page , get your image url as string _imgURL =Request.QueryString["imgURL"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM