Creating a grid layout that activates an image when clicked using JavaScript

I've successfully implemented a gridview with an image column, but I'm looking to enhance the functionality. Specifically, I want to enlarge the clicked image and bring it into focus on the screen. I've managed to achieve this when the images are not within a gridview, but I need them to be part of the gridview. Here is the CSS I'm using to handle the focusing:

#overlay {
        position: fixed;
        width: 100%;
        height: 100%;
        top: 0px;
        left: 0px;
        background-color: #000;
        opacity: 0.7;
        filter: alpha(opacity = 70) !important;
        display: none;
        z-index: 100;
    }

    #overlayContent {
        position: fixed;
        width: 100%;
        top: 100px;
        text-align: center;
        display: none;
        overflow: hidden;
        z-index: 100;
    }

    #contentGallery {
        margin: 0px auto;
    }

    #imgBig, #imgSmall {
        cursor: pointer;
    }

Here is my gridview markup:

<asp:GridView ID="GridViewEvents" CssClass="mGrid" AutoGenerateColumns="false" runat="server" DataSourceID="EntityDataSourceEvents">
    <Columns>
        <asp:TemplateField HeaderText="Vehicle">
            <ItemTemplate>
                <%#GetPlate(Convert.ToInt16(Eval("CarId"))) %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Driver">
            <ItemTemplate>
                <%#GetDriverId(Convert.ToInt16(Eval("DriverId"))) %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Start KM">
            <ItemTemplate>
                <div id="overlayContent">
                    <img id="imgBig" src="" alt="" />
                </div>
                <div id="grid">
                    <img id="imgSmall" onclick="Tiklandi()" alt="" src='<%#Eval("FirstKmImage") %>' />
                </div>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="End KM">
            <ItemTemplate>
                <asp:Image ID="ImageLast" ImageUrl='<%#Eval("LastKmImage") %>' runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Start Date">
            <ItemTemplate>
                <%#Eval("FirstDate") %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="End Date">
            <ItemTemplate>
                <%#Eval("LastDate") %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Route">
            <ItemTemplate>
                <%#Eval("Route") %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Status">
            <ItemTemplate>
                <%#Status(Convert.ToBoolean(Eval("Done")))%>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Here is my JavaScript code:

function Tiklandi() {
        $("#imgBig").attr("src", $(this).prop('src'));
        $("#overlay").show('slow');
        $("#overlayContent").show('slow');
    }

Any ideas on how I can modify my JavaScript code to achieve the desired functionality within the gridview?

Answer №1

Perhaps consider applying a class to the <img> tag.

<asp:Image ID="ImageLast" ImageUrl='<%#Eval("LastKmImage") %>' runat="server" class="Tiklandi" />

Then, connect the click event handler to the specified class.

$('.Tiklandi').click(function() {
        $("#imgBig").attr("src", $(this).prop('src'));
        $("#overlay").show('slow');
        $("#overlayContent").show('slow');
    })

Hopefully, this information proves useful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on saving an HTML table as an Excel file using ASP.NET C#

My HTML table looks like this: <table cellpadding="0" cellspacing="0" border="0" class="Messages" id="idTbl" runat="server"> <tr> <th>date</th> <th>Subject</th> </tr> <tr class="myHo ...

What is the reason behind arr.reverse() flipping the original array?

My goal is to reverse an array and store the reversed version in a new array without altering the original array. Here is the code I am using: var arr= ["1", "2", "5"] var arrTwo = arr.reverse(); console.log(arrTwo) \\ ["5" , "2" , "1"] console. ...

The React Hook useEffect is missing a dependency: 'handleLogout'. Make sure to either add it to the dependency array or remove it from the useEffect hook

import { useState, useEffect } from "react"; import LoginModal from "./LoginModal"; import { NavLink, useLocation, useNavigate } from "react-router-dom"; import { useDispatch } from "react-redux"; import { userLogout ...

Using Highmaps in a VueJs application involves passing a state to the mapOptions for customization

I'm currently struggling with passing a vuex state to mapOptions in vuejs components. Here is the code snippet: <template> <div> <highcharts :constructor-type="'mapChart'" :options="mapOptions" class="map">&l ...

Looking for assistance with arranging and managing several containers, buttons, and modals?

My goal is to create a grid of photos that, when hovered over, display a button that can be clicked to open a modal. I initially got one photo to work with this functionality, but as I added more photos and buttons, I encountered an issue where the first b ...

Conceal a table with jQuery

Is there a way to initially conceal a table on page load only to reveal it with a sliding animation when a specific link is clicked? I have attempted using the following code to hide the table: $('.table_div').hide(); I have enclosed the table ...

Error: The function 'check' is not defined and cannot be called when the 'on

My aim is to display the "expandrepeat" div when a specific select option is chosen. Unfortunately, the code below doesn't seem to be working as intended: <script> window.check=function(elem) { if (elem.selectedIndex == 1) { documen ...

Utilize the value of one variable to determine access to another variable in Javascript

I am working with several boolean variables and I want to create a new variable that keeps track of the most recently changed boolean variable. This way, every time a new boolean variable is modified, I can toggle the previous one. If you have any ideas o ...

How come my div doesn't stick together with the other div while moving?

I am trying to figure out how to make the blue "shield" div cover the red "button" div after 3 clicks successfully. It seems like no matter what I do, the positioning is always off. I've played around with the randomplace variable, but nothing seems t ...

Looking for a specific search term within the middle of strings in an array

Is there a way to improve the autocomplete feature of my input field so that it shows suggestions based on any part of the word typed in? I currently have it set up to only show suggestions if the input matches the start of a word in the array. How can I m ...

Interact with an element on one page and watch as it dynamically affects another element on a separate page using J

Is it possible to use jQuery to click a button on one page (index1.html) and change the color of text on another html page (index2.html)? I've tried various methods, but none seem to work due to the need to refresh the second page in order to view ch ...

Sketch the borders of the element (animated)

Seeking a way to create a button with an animated border that looks like it is being drawn. Current progress involves some code, but it's not working smoothly with border-radius set. (keep an eye on the corners) https://codepen.io/anon/pen/MbWagQ & ...

Rotating and scaling an image simultaneously using CSS3

I am feeling very puzzled. Why am I unable to simultaneously scale and rotate? Despite my attempts, it seems to be not working: .rotate-img{ -webkit-transform:scale(2,2); -webkit-transform:rotate(90deg); margin-left:20%; margin-top:10%; } ...

What is the best way to extract values from promises that are still pending?

Having some issues with the code below and unable to achieve the desired output. Any help in identifying what's wrong would be greatly appreciated. Thanks! Here is the code: // Making http requests const getJSON = require('get-json'); ...

Synchronous JavaScript function with live update

I'm currently working on a function that performs a lengthy task, and I'm looking to implement a feature that notifies the caller of the progress. My end goal is to update the user interface with the current progress status. Here's an examp ...

Leveraging jQuery's $.getJSON method to fetch localization data from aprs.fi

Utilizing JSON to retrieve localization coordinates from is my current goal. I came across an example on http://api.jquery.com/jQuery.getJSON: <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?", { tags: ...

Transfer information from the server to the client using NodeJS and Express

I am encountering an issue with sending data from my express server to the client side. I have implemented app.post and app.get, however the problem is that the request needs to originate from the client side. My requirement is to send the data from the se ...

populate vueJS table with data

I encountered an issue while trying to load data from the database into my table created in VueJS. I have set up my component table and my script in app.js, but I am seeing the following error in the view: [Vue warn]: Property or method "datosUsuario" ...

You can click on the link within the Leaflet Popup to trigger JavaScript functionality

My leaflet map is functioning with GeoJSON polygons and popups attached to each one. These popups display information about the polygon. I want a link inside the popup that, when clicked, triggers a JavaScript function to retrieve and display smaller polyg ...

Javascript time conflict dilemma

Currently, I am working on the add task module for my project. I need to ensure that whenever a task is added, it does not overlap with existing tasks. I have almost completed this functionality, but I have encountered a problem specifically with time over ...