简体   繁体   中英

Showing Picture in Asp.Net Image Control From Datalist

I am using Asp.Net C# 4.0. I have a Datalist which shows pictures from database. My question is, Is it possible to show pictures in asp.net image control from a datalist upon clicking? The purpose of this operation is to enlarge the picture upon clicking. I am using the following code.

//Here is my ObjectDataSource
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
    SelectMethod="ShowPicBA" TypeName="BusinessAccess.AD_OperationBA">
    <SelectParameters>
        <asp:QueryStringParameter Name="key" QueryStringField="id" Type="Int64" />
    </SelectParameters>
</asp:ObjectDataSource>


//Here is my DataList
<asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource2" 
        DataKeyField="Pic_ID">
        <ItemTemplate>
            <asp:ImageButton ID="ImageButton1" runat="server" Height="152px"
                ImageUrl='<%# Eval("Pic_Path") %>' Width="175px"/>
        </ItemTemplate>
    </asp:DataList>

//Here is my Asp.Net Image Control
<asp:Image ID="Image1" runat="server" />

you can do this through javascript.

Add onClientClick to the ImageButton

<asp:ImageButton ID="ImageButton1" runat="server" Height="152px"
 ImageUrl='<%# Eval("Pic_Path") %>' Width="175px" onclientclick="ChangeImage(this);return false;"/>

function ChangeImage(Src) {
    document.getElementById('<%=Image1.ClientID%>').src = Src.src;
    return false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM