1

我想尝试从 Datalist 中的四个 imageButons 更改图像 url,但即使我在尝试我也不知道如何

这是我的数据列表

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

这是我的 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

希望我足够清楚,你可以帮助我!

4

1 回答 1

1

请在您的 aspx.vb 页面中进行如下更改:

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
于 2013-11-13T19:19:20.867 回答