Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

XML
<asp:DataList RepeatColumns="3" ID="repdetails"     runat="server">
                           <ItemTemplate>
                           <table><tr><td style="border:1px solid #bfbfbf; width:50px;">
                                <asp:ImageButton ID="imgbtnid" runat="server" Width="40"
                OnClientClick="return   imagepopup(this.src);" Height="40" ImageUrl='<%# Eval("ivtf_docs_id", "../Imagenew.ashx?styleid={0}")%>'/>
                           </td></tr></table>
                           </ItemTemplate>
                           </asp:DataList>


When the page shows on browser, I have list of images in DataList. Now I need to get index of clicked image from DataList.
if I click first image, it should get index 0 , if it is second image, index should be 1 and etc..

JavaScript
function imagepopup(thmsubimg) {
                   // here how to get index of clicked image from datalist.
                  return false;
               }


Help needed
Posted
Updated 12-Mar-15 2:44am
v2
Comments
Mohibur Rashid 12-Mar-15 5:39am    
Jquery is javascript. If you do not know that then it wont be easy for you to get the concept. Anyway, you can store custom data in your image Attributes and the use setAttribute to set and getAttribute to get the desired data. Give it a try.

1 solution

The problem is that you have Table inside the DataList. So, for each row of DataList, you will actually get many Tables and then their rows and then inside the td, you have the Image.

So, if you click on image and get into the function you have written, then you need to actually count the number of Images inside the main DataList Table and according to that find the index of that particular Image. That is because you are getting 3 columns (td) inside one row. So, when you will calculate according to the parent td index, you will find 0, 1, 2 for the first three images. Then next set of images who are in the next row, will be the same like 0, 1, 2. You won't get the actual index unless you calculate.

Please see the rendered HTML on browser and you will be clarified what I am talking about. Saying that, I would suggest you to redesign the markup or think of the logic which will fit into the correct structure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900