Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Here is my code, then i will ask my question below.

JavaScript
 var GridView = document.getElementById('<%=gridUploads.ClientID %>')
    if (GridView.rows.length > 0) {
        for (var i = 1; i < GridView.rows.length; i++) {
//find controls
 var modal = GridView.rows[i].getElementById('<%= myModal.ClientID %>')
}


My modal decoration is in an item-template in a c# grid-view called gridUploads. I would like to find the modal control in javascript, how would i do this?


the control i am trying to grab is
1. a modal
2. other elements like an input, img etc.

if i can figure out how to find the modal, i can pretty much figure the rest out.

here is the declaration of the elements, if you feel it would help.


ASP.NET
<ItemTemplate>...
     <asp:Panel ID="pnluploads1" runat="server">
           <div class="scans-container">
           <div class="scanimage">
           <input class="hideelement toggle" id="'<%#Container.DataItemIndex.ToString() %>'" type="checkbox" checked="checked">
            <label class="lblscanImg"  for="'<%#Eval("ClientOrderNo") %><%#Container.DataItemIndex.ToString() %>'"> view scan</label>
           <div id="expand">
           <img id="myImg" src="../../img/test.jpg" width="300" height="200">
</div>
</div>
</div>
<!-- The Modal -->
    <div id="myModal" class="modal">
    <span class="close">×</span>
     <img class="modal-content" id="img01" src="#">
     <div id="caption"></div>
       </div>
...
</ItemTemplate>




thanks so much for your help.

What I have tried:

I have tried

1) var modal = GridView.rows[i].getElementById('myModal');
//returned null.

2) var modal = document.getElementById('<%=((gridUploads)Container).FindControl("myModal").ClientID %>'); 
//grid couldn't find container
Posted
Updated 23-Feb-18 3:40am
v2
Comments
F-ES Sitecore 23-Feb-18 8:41am    
We can't really say from what you've provided. View the source of the page and see how the element you want to access is represented in html and use that to work out how to access it.

1 solution

Easiest method would be to find the items by class name

var grd = document.getElementById('<%=gridUploads.ClientID%>');
var m = grd.getElementsByClassName('modal');
for (var i = 0; i < m.length; i++) {
    var c = m[i].getElementsByTagName('div');
    c[0].innerHTML = 'Caption ' + i;
}
 
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