locked
display (3)rowx(3) column in gridview and display images from image folder RRS feed

  • Question

  •  

    anyone can suggest me how to display 3(row)x3(column) gridview and display images on that from images folder...

     

    display one images on gridview is working fine in localhost but after online it is not showing a images on gridview following is my code...

     

    public partial class _Default : System.Web.UI.Page

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    if (this.IsPostBack == false)

    {

    GridViewBinding();

    //bindGridView(Server.MapPath(@"~\AlbumCategoriesImages\"));

    }

    }

    private void GridViewBinding()

    {

    try

    {

    string dirServerMapPath = Server.MapPath(@"AlbumCategoriesImages");

    DirectoryInfo dir = new DirectoryInfo(dirServerMapPath);

    FileInfo[] fInfoArr = dir.GetFiles();

    if (fInfoArr.Length > 0)

    {

    DataTable tblAlbumRecords = new DataTable();

    DataColumn colPictureUrl = new DataColumn("PictureUrl", typeof(string));

    DataColumn colAlbumName = new DataColumn("AlbumName", typeof(string));

    DataColumn colAlbumSize = new DataColumn("AlbumSize", typeof(string));

    DataColumn colAlbumDate = new DataColumn("AlbumDate", typeof(string));

    tblAlbumRecords.Columns.Add(colPictureUrl);

    tblAlbumRecords.Columns.Add(colAlbumName);

    tblAlbumRecords.Columns.Add(colAlbumSize);

    tblAlbumRecords.Columns.Add(colAlbumDate);

    DataRow dRow;

    foreach (FileInfo File in fInfoArr)

    {

    dRow = tblAlbumRecords.NewRow();

    dRow[0] = Server.MapPath(@"AlbumCategoriesImages" + File.Name);

    dRow[1] = DeleteFileExtension(File.Name);

    //Album Folder Images count

    string folderName = DeleteFileExtension(File.Name);

    string[] folderImages = Directory.GetFiles(Server.MapPath(folderName), "*.*");

    int totalImages = folderImages.Length;

    //end Code

    dRow[2] = totalImages.ToString();

    dRow[3] = File.CreationTime.Day + "-" + File.CreationTime.Month + "-" + File.CreationTime.Year;

    tblAlbumRecords.Rows.Add(dRow);

    }

    GridView1.DataSource = tblAlbumRecords;

    GridView1.DataBind();

    }

    else

    {

    Response.Write("Records Not Found");

    }

    }

    catch (Exception ex)

    {

    Response.Write("Error : " + ex.Message.ToString());

    }

    }

    private string DeleteFileExtension(string fileName)

    {

    return fileName.Remove(fileName.Length - 4, 4);

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

    {

    if (e.CommandName == "cmdImg")

    {

    Response.Redirect("SelectAlbumSubImages.aspx?AlbumName=" + e.CommandArgument);

    }

    }

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

    GridView1.PageIndex = e.NewPageIndex;

    GridViewBinding();

    }

    }
    Monday, November 3, 2008 12:32 PM