简体   繁体   中英

get client id of image control inside repeater inside gridview

How do I get client id of image control

<asp:GridView ID="gv" OnRowDataBound="GetItems" runat="server" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" Font-Names="tahoma" Font-Size="8pt" AutoGenerateColumns="False" Height="154px" Width="929px">
    <Columns>
          <asp:TemplateField HeaderText="pic">
            <ItemTemplate>
                <asp:Repeater ID="pictures" runat="server">
                    <ItemTemplate> 
                        <asp:Image ID="Image1" runat="server" height="120" width="90"  ImageUrl='<%# Eval("ImageUrl") %>' onclick="DisplayNewImageInWidnow();" />  
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

I use this code but it doesn't work

function DisplayNewImageInWidnow()
{
    var img = document.getElementById('<%=gv.FindControl("pictures").FindControl("Image1").ClientID %>').src
OnClientClick="return DisplayNewImageInWidnow();"

or prevent server side from running

OnClientClick="DisplayNewImageInWidnow();return false;"

then

function DisplayNewImageInWidnow(obj)
{
    var imgId = obj.id;
}

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