Asp VB - 想要在datalist中更改图像URL

时间:2013-11-13 17:01:52

标签: asp.net vb.net datalist

我想尝试从Datalist中的四个imageButons更改一个Image 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
希望我足够清楚,你可以帮助我!

1 个答案:

答案 0 :(得分: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