locked
display image in panel when datalist row is clicked RRS feed

  • Question

  • User-520535568 posted

    HI, I have a datalist which displays a list of staff, when a row is selected a Panel appears showing more details. This is the code that fires the Panel (Panel2):

        Protected Sub MoreBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Panel1.Visible = False
            Panel2.Visible = True
        End Sub

    Then I grab the details from the datalist and show them in Panel2 like this:

        Protected Sub DataList4_ItemCommand(source As Object, e As DataListCommandEventArgs)
    
            If e.CommandName = "Link" Then
                Dim label1 As Label = DirectCast(DataList4.Items(e.Item.ItemIndex).FindControl("Label1"), Label)
                Dim label2 As Label = DirectCast(DataList4.Items(e.Item.ItemIndex).FindControl("Label2"), Label)
                Dim label3 As Label = DirectCast(DataList4.Items(e.Item.ItemIndex).FindControl("Label3"), Label)
                Dim label4 As Label = DirectCast(DataList4.Items(e.Item.ItemIndex).FindControl("Label4"), Label)
                Dim label5 As Label = DirectCast(DataList4.Items(e.Item.ItemIndex).FindControl("Label5"), Label)
                UserNameBox.Text = label1.Text
                PostBox.Text = label2.Text
                SectionBox.Text = label3.Text
                ServiceBox.Text = label4.Text
                PhotoBox.Text = label5.Text
            End If
            
        End Sub

    This all works fine but what I'd also like is to show the corresponding photo in Panel2 alongside the details.

    I've tried passing the photo URL into the Panel via PhotoBox.Text but obviously this just shows the path to the photo.

    Any help is much appreciated.

    Monday, February 6, 2017 9:50 AM

Answers

  • User-520535568 posted

    Fixed it with this:

    Image1.ImageURL = label5.Text

    And displayed it in the Panel with this:

    <asp:Image  ID="Image1" runat="server" ImageUrl='<%# Eval("label5.Text")%>' />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2017 11:06 AM

All replies

  • User-520535568 posted

    Fixed it with this:

    Image1.ImageURL = label5.Text

    And displayed it in the Panel with this:

    <asp:Image  ID="Image1" runat="server" ImageUrl='<%# Eval("label5.Text")%>' />

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 6, 2017 11:06 AM
  • User-1716253493 posted

    Use asp:image

    Image1.ImageUrl = "~/Photos/" & label5.Text

    Monday, February 6, 2017 12:21 PM