Question

I want to try to change an Image url from four imageButons inside a Datalist, but even I am trying I don't know how

Here is my datalist

  <asp:DataList ID="DataList1" runat="server" CellPadding="4" 
    ForeColor="#333333" OnItemCommand="ItemCommand">
    <AlternatingItemStyle BackColor="#2E2E2E" />
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <ItemStyle BackColor="#151515" />
    <ItemTemplate>
              <div id="hiden" class="categorry">
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <ContentTemplate>
            <table style="margin-left:250px;" width="360px" >
            <tr><td colspan="5" height="160px"><asp:Image ID="Image1" imageurl='<%# Eval("Mainfoto") %>'  width="360px" height="230px" runat="server" /> </td></tr>
            <tr><td width="90px"><asp:ImageButton ID="ImageButton1" imageurl='<%# Eval("Mainfoto") %>' CommandName ="ImageButton1"  width="80px" height="70px" runat="server" /> </td>
                <td width="90px"><asp:ImageButton  ID="ImageButton2" imageurl='<%# Eval("Foto2") %>'   CommandName ="ImageButton2"  width="80px" height="70px" runat="server" /> </td>
                <td width="90px"><asp:ImageButton  ID="ImageButton3" imageurl='<%# Eval("Foto3") %>'  width="80px" height="70px" runat="server" /> </td>
                <td width="90px"><asp:ImageButton  ID="ImageButton4" imageurl='<%# Eval("Foto4") %>'  width="80px" height="70px" runat="server" /></td></tr>
            </table>
             </ContentTemplate>
            </asp:UpdatePanel>
             </div>



    </ItemTemplate>
    <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:DataList>

and here is my aspx.vb

   Protected Sub ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
    Dim myListItem As DataListItem = CType(source, DataList).SelectedItem
    Dim l As ImageButton = myListItem.FindControl("ImageButton2")
    Dim img As Image = myListItem.FindControl("Image1")
    If e.CommandName = "ImageButton2" Then

        img.ImageUrl = l.ImageUrl
    End If
End Sub

hope I am clear enough, and you can help me!

Was it helpful?

Solution

Please make changes in your aspx.vb page as follow :

Protected Sub ItemCommand(source As Object, e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles DataList1.ItemCommand
    Dim myListItem As DataListItem = e.Item
    Dim l As ImageButton = myListItem.FindControl("ImageButton2")
    Dim img As Image = myListItem.FindControl("Image1")
    If e.CommandName = "ImageButton2" Then

        img.ImageUrl = l.ImageUrl
    End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top