title: How to display image in asp.net from folder
body: <p>I need to display image from folder in asp.net datalist control. I have written following code but getting full path of file name.
  here my code is</p>
  
  <p>//HTML element</p>
  
  <pre><code>&lt;asp:DataList CssClass= ID="DataList1" runat="server" RepeatColumns="5" 
          RepeatDirection="Horizontal" Width="100%"&gt;
      &lt;ItemTemplate&gt;
          &lt;div class="image-container"&gt;
              &lt;div class="image"&gt;
               &lt;asp:Image ID="Image" runat="server" Height="150px" Width="150px" ImageUrl='&lt;%# Container.DataItem %&gt;' /&gt;
              &lt;/div&gt;
              &lt;div class="file-name"&gt;
                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Container.DataItem %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:DataList&gt;
  </code></pre>
  
  <p>//Code Behind</p>
  
  <pre><code> public void displayimage ()
  
      {
  
          string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/images"));
          List&lt;String&gt; images = new List&lt;string&gt;(filesindirectory.Count());
  
  
  
          foreach (string items in filesindirectory)
          {
              images.Add(String.Format("~/images/{0}", Path.GetFileName(items)));
          }
  
  
  
          PagedDataSource obj = new PagedDataSource();
          obj.DataSource = images;
          obj.AllowPaging = true;
          obj.PageSize = 5;
          obj.CurrentPageIndex = currentpage;
          Label4.Text = "Page : " + (currentpage + 1).ToString() + " of " + obj.PageCount.ToString();
          Btn_Previous.Enabled = !obj.IsFirstPage;
          Btn_next.Enabled = !obj.IsLastPage;
          DataList1.DataSource = obj;
          DataList1.DataBind();
      }
  </code></pre>
  
  <p>Please help</p>