Next and Previous buttons in jquery image gallery

Next and Previous buttons in jquery image gallery

I want to code the next and previous buttons for my jquery image gallery. When i click on next button, it shows me the first image of the gallery and then it stops working for any other image. Can someone help me what i am doung wrong in my code? Please help? Below is jquery.
  1. <script type="text/javascript">
  2.         jQuery(document).ready(function () {
  3.             jQuery('.item').click(function () {
  4.                 // Getting "src" attribute of the image that was clicked.
  5.                 var path = jQuery(this).find('img').attr('src');
  6.                 document.getElementById('tempVal').value = path;
  7.                 // Setting "src" attribute of the big image.
  8.                 jQuery('#big img').attr('src', path);
  9.                 jQuery('#bcktopainting').attr('style', 'display:normal;');
  10.             });
  11.             jQuery('#bcktopainting').click(function () {
  12.                 jQuery('#big img').attr('src', '');
  13.                 jQuery('#bcktopainting').attr('style', 'display:none;')
  14.             });
  15.             jQuery('.next').click(function () {
  16.                 var currentItem = document.getElementById('tempVal').value;
  17.                 currentItem.next();
  18.                 var nextPath = jQuery('ul').find('li').find('img').attr('src', currentItem).next();
  19.                 jQuery('#big img').attr('src', nextPath);
  20.             });
  21.         });
Below is HTML:

  1. <body>
  2.     <input type="hidden" id="tempVal" name="tempValues" value="" style="display: none;" />
  3.     <main class="page payment-page">
  4.         <section class="payment-form dark">
  5.             <div class="container">
  6.                 <div class="block-heading">
  7.                     <a href="Index.aspx">
  8.                         <img src="assets/images/kmac_logo.jpg" />
  9.                     </a>
  10.                     <center>
  11.               <nav class="navbar navbar-default navigation-clean-button" style="width: 350px;">
  12.                 <div class="navbar-header">
  13.                   <button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navcol-1"><span class="sr-only">Toggle navigation</span><span class="icon-bar"></span>
  14.                     <span class="icon-bar"></span><span class="icon-bar"></span></button>
  15.                   </div>
  16.                   <div class="collapse navbar-collapse" id="navcol-1">
  17.                     <ul class="nav navbar-nav">
  18.                       <li role="presentation"><a href="Painting.aspx">Painting</a></li>
  19.                       <li role="presentation"><a href="Painting2.aspx">Painting 2</a></li>
  20.                       <li role="presentation"><a href="Contact.aspx">Contact</a></li>
  21.                     </ul>
  22.                   </div>
  23.                 </nav>
  24.               </center>
  25.                 </div>
  26.                 <form runat="server" id="big">
  27.                     <img src="" />
  28.                     <div class="card-details">
  29.                         <p id="bcktopainting" style="display: none; float: left;">Back To Painting</p>
  30.                         <p style="" id="prev" onclick="showPrev();">Previous</p>
  31.                         /<p style="" id="next" class="next">Next</p>
  32.                     </div>
  33.                 </form>
  34.                 <section class="gallery-block grid-gallery">
  35.                     <div class="container">
  36.                         <ul class="row" id="row" runat="server">
  37.                         </ul>
  38.                     </div>
  39.                 </section>
  40.             </div>
  41.         </section>
  42.     </main>
  43. </body>
And Below is my ASP.NET code for fetching the images.

  1. public partial class Painting : System.Web.UI.Page
  2.     {
  3.         protected void Page_Load(object sender, EventArgs e)
  4.         {
  5.             imageRetriever();
  6.         }

  7.         private void imageRetriever()
  8.         {
  9.             StringBuilder table = new StringBuilder();
  10.             foreach (string strFileName in Directory.GetFiles(Server.MapPath("PaintingPagePictures/")))
  11.             {
  12.                 FileInfo fileInfo = new FileInfo(strFileName);
  13.                 table.Append("<li class=\"col-md-6 col-lg-4 item\">");
  14.                 table.Append("<img class=\"img - fluid image scale - on - hover\" src=\"PaintingPagePictures/" + fileInfo.Name + "\" />");
  15.                 table.Append("</li>");
  16.             }
  17.             row.InnerHtml = table.ToString();
  18.         }
  19.     }