In img tag your are missing ID property
add Id <img src=\"/ImageHandler.ashx?id=img" + r["ID"].ToString() + "&width=35&height=16\" alt=\"\" runat=\"server\" id=img" + r["ID"].ToString() + "/>
Use Jquery to get the all the ids in javascript. like below
var IDs = [];
$("#a").find("img").each(function () { IDs.push(this.id); });
at UI
<div id="a" runat="server">
</div>
Use String builder class and add your HTMLto the div id "a"