kukula 0 Newbie Poster

Hi Everyone,
I have problem with Image Control in my asp.net site.
Mainly I have to make some kind of photo gallery. So I used FileUpload control to send parameters: ID and Comment to my SQL DB, and my photos to one of the solution's folder. I want to display ID and Comment and name of the photo in GridView. I also added a button to GridView to open chosen image in Image Control which is below GridView.
When user open my gallery site in Image Control shows up first image from GridView list. But when I click button to show another image Image Control dissapear. From this moment nothing shows up in my Image Control.

Here is C# code:

using System;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web.UI.WebControls;
using System.IO;

public partial class gallery_ready : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
           
        BazaDataContext db = new BazaDataContext();
        string foto = "Images" +@"\" +(from zdj in db.Obrazies  select zdj.Image).FirstOrDefault().ToString();
        Image1.ImageUrl =  foto;
        Label1.Text = foto.ToString();          
        
    }
    
       protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        

        GridViewRow row = GridView2.SelectedRow;
        int rzad = row.RowIndex;
        LabelInfo.Text = rzad.ToString();
        
        Image img = null;
        BazaDataContext db = new BazaDataContext();
        string foto = (from zdj in db.Obrazies where zdj.ID == GridView2.SelectedIndex + 1 select zdj.Image).ToString();
        Image1.ImageUrl = "Images\\" + foto;
        Label2.Text = foto.ToString();
    }
    protected void GridView2_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        GridViewRow row = GridView2.Rows[e.NewSelectedIndex];
        int rzad = row.RowIndex;
        Label1.Text = rzad.ToString();
    }
    private string nazwa = "";


protected void  GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName == "Wyswietl")
    {
        int indeks = Convert.ToInt16(e.CommandArgument);
        nazwa = GridView2.Rows[indeks].Cells[2].Text;

      
        string folder = Server.MapPath("~/Images/");
        string sciezka = folder + nazwa;
        Image1.ImageUrl = sciezka;
        LabelInfo.Text = sciezka;
    }
    
}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.