i am new to asp.net c#. i am trying to retireve all images from folder and show it on page, but it's only selecting one image.

My asp.net code.

<form id="form1" runat="server" class="col-lg-5">

        <asp:Image ID="Image" runat="server" />

My C# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

namespace Blog
    public partial class index : System.Web.UI.Page
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["blogconnection"].ToString());
        protected void Page_Load(object sender, EventArgs e)
           string allimage;
            string qry="select * from images";
            SqlCommand cmd = new SqlCommand(qry, con);
            SqlDataReader dr =cmd.ExecuteReader();

           if (dr.HasRows)
                if (!string.IsNullOrEmpty(Convert.ToString(dr["Image_Path"])))

                        Image.ImageUrl = Convert.ToString(dr["Image_Path"]);



What I want: i want to select all image which path is store in sql table.

Additional: is there a way to select videos from folder which path is store in sql, mean to select videos and images from different folder and show both on same page by date specified or by latest upload etc.

Any help will be appreciated.

Edit #1

In php i use the below code to get all images and show it, is there any thing equilent to the below code in asp.net?

PHP Code

include 'conn.php';
$smt=$conn->prepare('SELECT * FROM post');

<?php include 'header.php';

<div class="">
include 'nav.php';
include 'nav-simple.php';
<?php include 'slider.php';?>

<?php include 'right_sidebar.php';?>

    <div class="col-md-1 top_space"></div>
<div class="container col-md-8 main-container-top">


<div class="">
    <?php while ($gdata = $smt->fetch(PDO::FETCH_OBJ)): ?>
        <a href="#" class="col-md-4"><img src="posts/<?php echo $gdata->Post_Path; ?>" alt="image" class="post-image"/></a>
        <div class="media-body col-md-8 post pull-left">
            <div class="post-overview">
                    <li class="post-category"><?php echo $gdata->Category; ?></li>
                    <li class="post-timestemp">Post on <?php echo $gdata->Post_Date; ?></li>

                <a href="post-description.php?id=<?php echo $gdata->Id ?>"><h4
                        class="media-heading h4"><?php echo $gdata->Title; ?></h4></a>

                <p class="post-text"><?php echo $gdata->Post; ?></p><br/>

<div class="post-image-space"></div>
    <?php endwhile;?>


Related posts

Recent Viewed