I have a list of images that are pulled from a database and loaded into a ListView in ASP. I have a JQuery click function attached to each image that is generated. What I need to do is somehow get the id of the image that is clicked, but right now, I dont see a way to attach an ID to each image.
The ListView is populated from a SQLSource that has the columns ID, UserName, Photo. The item template uses username and photo to display the list, but will not let me set the ID using Eval(“fieldName”).
What I’m trying to do is: when the user clicks the image, the ID associated with that image is grabbed by JQuery, which opens up another window and uses that ID has part of a querystring. Ex:
window.open(“anotherpage.aspx?id=” + imgID);
Here is the jquery I have right now:
<script type="text/javascript">
jQuery(document).ready(function () {
$('[class=originalPhoto]').click(function (event) {
var url = $(this).attr("href");
var windowName = "popup";
window.open("test.aspx");
event.preventDefault();
});
});
</script>
And the listview:
<telerik:RadListView ID="photoList" runat="server"
DataSourceID="employeePicsSource" DataKeyNames="ID">
<ItemTemplate>
<center>
<p>
<table border="0" width="1000" cellpadding="10" class="personnelCell">
<tr>
<td width="25%"><%#Eval("FullName") %></td>
<td width="25%"><%#Eval("ADGUID") %></td>
<td width="25%" align="center"><asp:Image runat="server"
ImageUrl='<%#GetImageURL((int)DataBinder.Eval(Container.DataItem,"ID")) %>'
Width="200" CssClass="originalPhoto" /></td>
<td width="25%"><asp:Image runat="server" Width="96" Height="96" /></td>
</tr>
</table>
</p>
</center>
</ItemTemplate>
</telerik:RadListView>
<asp:SqlDataSource ID="employeePicsSource" runat="server"
ConnectionString="<%$ ConnectionStrings:Employee_Photos_DevConnectionString %>"
SelectCommand="SELECT [FullName], [ADGUID], [Photo], [ID] FROM [Employee_AndPhoto]">
</asp:SqlDataSource>
Any ideas? TIA
In the same way you get the href you can have the id as well
As jostster says, you also need to add the id to you image, something like