1

I am working on class project where I am creating a listview in one .aspx page. I can display database through this list view but I cannot transfer the value of selected item from this .aspx page to another.

My designing code is like below:

<asp:ListView ID="lvPresent" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="lvPresent_ItemDataBound" >
        <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>

What should I do to get this work done ?

  • Have a look at the [HyperLinkField](https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield(v=vs.110).aspx) control. It has properties for passing the URL via query string. – mason Mar 16 '15 at 20:40
  • @saif14 what do you meant by selected items? is these any checkbox? – Sharique Ansari Mar 17 '15 at 10:36
  • @sharique, no its not checkbox. What i meant was I wanted to select a image from the listitem. The listitem was for creating an image gallery. So i click on an image, it would go to another page and show that particular picture. – Saif Mahmud Parvez Mar 17 '15 at 12:37
  • @saif14 see my answer here [here](http://stackoverflow.com/questions/29094319/how-can-i-pass-the-url-of-a-selected-image-which-is-included-in-a-listview-from/29094697#29094697) – Sharique Ansari Mar 17 '15 at 12:48
  • on that page, you can access image url using `string imgurl = Request.QueryString["imgURL"];` & put an image control in that page assign this image on page load – Sharique Ansari Mar 17 '15 at 12:50
  • if your image control id is Image1 then you can assign on page load of that page `image1.ImageUrl=imgurl` – Sharique Ansari Mar 17 '15 at 12:51
  • you can mark as asnwer if it help you – Sharique Ansari Mar 17 '15 at 12:52

3 Answers3

1

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>

On that page, you can access image url like this:-

string imgurl = Request.QueryString["imgURL"];

Put an image control in that page assign this image on page load, if your image control id is Image1 then you can assign on page load of that page like this:-

Image1.ImageUrl = imgurl

Sharique Ansari
  • 534
  • 5
  • 12
0

Look into server.transfer or response.redirect to pass data between pages..

A link on SO on the difference between the 2 and what they do:

Server.Transfer Vs. Response.Redirect

Community
  • 1
  • 1
JustAPup
  • 1,720
  • 12
  • 19
0
  1. You can redirect to the other page and send the value in a query string

  2. You can send the value in a session object