开发者

How to get the images src which are in template field of gridview

开发者 https://www.devze.com 2023-03-22 08:06 出处:网络
<asp:TemplateField HeaderText=\"Picture\" ItemStyle-Height = \"150\" ItemStyle-Width = \"170\">
<asp:TemplateField HeaderText="Picture" ItemStyle-Height = "150" ItemStyle-Width = "170">
    <ItemTemplate>
        <asp:Image ID="Image1" runat="server" Height="150" Width="150"
           ImageUrl = '开发者_开发知识库<%# Eval("PicturePath", GetUrl("{0}")) %>'/>
    </ItemTemplate> 
    <ControlStyle Height="150" Width="150" />
    <ItemStyle Height="150" Width="150"></ItemStyle>
</asp:TemplateField>

I know how to get images src by using getElementById.But my requirement is to get image src from gridview template field.I just want to display all the images src which are in grid into list box.src should be like src="http://localhost:61027/Images/JellyFish.jpg"


You should be able to get the underlaying data item in the GridView RowDataBound Event. If your Listbox id is lbImageSource, for example, then here is the code you'll want:

If e.Row.RowType = DataControlRowType.DataRow Then
Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView)
lbImageSource.Items.Add(String.Format("src=""{0}""", drv("PicturePath").ToString()))
End If

You'll probably want to clear the listbox at some point as well. The GridView DataBinding event should work for that.

lbImageSource.Items.Clear()


Method 1 (pass the variable to the front end):

  • When the server is binding, add all the src to an object and render it as a hidden div so the front end can have it

Method 2 (grab it with jQuery):

  • $('#<%= YourGrid.ClientID %> img');
  • That will get you all the img items so you can iterate through them to get the src
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号