Jump to content
diogom

carregar foto para gridview

Recommended Posts

diogom

olá,

Estou a fazer um site e utilizo uma gridview.

O problema é que não consigo carregar as fotos da base de dados para a gridview, o restante carrega sem problema.

O codigo:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            carregardados();
        }
    }
    public void carregardados()
    {
        //Ocultar resultados
        GridView1.Visible = false;
        //Label1.Text = "";

        string query = ("SELECT * FROM imagens");

        String SERVIDOR = "localhost";
        String BANCO = "";
        String USUARIO = "";
        String SENHA = "";

        String stringConexao = "Database=" + BANCO + ";Data Source=" + SERVIDOR + ";User Id=" + USUARIO + ";Password=" + SENHA + "; pooling=false";

        MySqlConnection conexao = new MySqlConnection(stringConexao);

   
        MySqlDataAdapter myAdapter = new MySqlDataAdapter();


        DataSet dataset = new DataSet();
        try
        {

            myAdapter.SelectCommand = new MySqlCommand(query, conexao);

            myAdapter.Fill(dataset);

            GridView1.DataSource = dataset;

            GridView1.DataBind();

            GridView1.Visible = true;


        }
        catch (MySqlException erro)
        {
            
            // Label1.Text = erro.Message;
            MessageBox.Show("erro " + erro);
        }
        finally
        {
          
            dataset.Dispose();
            myAdapter.Dispose();
            conexao.Close();
            conexao.Dispose();
        }
    }
}

Share this post


Link to post
Share on other sites
petvetbr

Share this post


Link to post
Share on other sites
poliveira1978

podes usar o objecto asp:image no ficheiro aspx e defines a propriedade ImageUrl da seguinte forma:

ImageUrl='<%#Eval("nome do campo da imagem na bd")%>'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.