I am working with ASP.NET. I am using a repeater to display images, and I also am using a check box for each image.

How can I select individual images and update their values as per image id?

My code is:

 <asp:Repeater ID="Repeater1" runat="server">
      <ItemTemplate>
           <img ID="ImageZoom" runat="server" 
                src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> '
                style="display: inline; height:auto; left: 0pt; top: 0pt;
                width:auto;" />
           <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
</asp:Repeater>
share|improve this question

0% accept rate
what do you exactly mean by "select individual image and update their value as per image id"? – Buzz Aug 22 at 6:18
I am saving a vaue for each image such as image name . if i select that image image , i am giving an option to change image text value. – user1570594 Aug 22 at 6:24
feedback

1 Answer

You could use javascript to implement this, something like this should do the trick:

Without jQuery

<asp:Repeater ID="Repeater1" runat="server">
      <ItemTemplate>
           <img ID="ImageZoom" runat="server"
                onclick="imageClickHandler(this,event);" 
                src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> '
                style="display: inline; height:auto; left: 0pt; top: 0pt;
                width:auto;" />
           <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
</asp:Repeater>

function imageClickHandler(s,e){
//do something with the current image that is being clicked on.
//The parameter 's' is a reference to the caller of this method and the 'e' contains
//event data  
}

With jQuery

If your using jQuery, you could also try something like this:

<asp:Repeater ID="Repeater1" runat="server">
      <ItemTemplate>
           <img ID="ImageZoom" runat="server"
                class="handled" 
                src='<%# DataBinder.Eval(Container.DataItem, "ImageUrl") %> '
                style="display: inline; height:auto; left: 0pt; top: 0pt;
                width:auto;" />
           <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
 </asp:Repeater>

<script type="text/javascript" src="jquery-1.7.3"></script>
$(function(){
  $("img.handled").click(function(){
    //alerts the id of the image thats being clicked on.
    alert($(this).attr("id"));
  });
});
share|improve this answer
Rob ANgelier : I want Image id of repeater in c# code on select of check box . how can i get this . I am using a button to upadate – user1570594 Aug 22 at 6:59
You should take a look at the following information: msdn.microsoft.com/en-us/library/… – Rob Angelier Aug 22 at 7:56
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.