I have gridview which contains a column containing a HTMLInput File Control (Upload Button), Also We have an image here, Here is the Code:
<ItemTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server" Visible='<%# Bind("IsfileUplo") %>'>
<div>
<table>
<tr>
<td>
<input id="Upload1" type="file" name="file" onchange="javascript:previewFile(this)" runat="server" accept="image/*" />
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td>
<asp:Image ID="Image2" runat="server" Height="100px" Width="100px" />
</td>
<td>
<asp:Label ID="Label5" runat="server" Text="" Width="120px"></asp:Label>
</td>
</tr>
</table>
</div>
</ItemTemplate>
After running website we have something like this:
As you can see there an Item Template with those controls in each row. Now I need to fire previewFile() javascript function which gets upload button and image ID and then will do something. Here is the code:
function previewFile() {
var preview = document.querySelector('#<%=Image2.ClientID %>');
var file = document.querySelector('#<%=Upload1.ClientID %>').files[0];}
The problem is here, It can not detect Image2 and Upload1 Controls inside Item Template of Grid View. I need to get the image path of selected picture with upload control and show it in image control in client side using this script. But I can not pass correct Control IDs to get it to work.
What should I do?