0
I’m doing an app on Asp.NET
, with Entity Framework
and using the database Oracle
and here’s the thing I’m uploading the image by a button
and saving in the database with the type BLOB
until then all right, but I need the image to appear on the screen along with information from another table called PRODUTOS
, I was thinking popular line by line with DataTable
, but because I couldn’t.
Database with BLOB image
Entity
Gridview with image
Gridview Rendered in browser
private void carregarImagem()
{
dt.Columns.Add("id");
dt.Columns.Add("nome");
dt.Columns.Add("valor_unit");
dt.Columns.Add("imagem1");
ProjetoContext bd = new ProjetoContext();
List<PRODUTO> produtos = bd.PRODUTOes.ToList();
List<IMG_PRODUTO> imagem = bd.IMG_PRODUTO.ToList();
foreach (PRODUTO pr in produtos)
{
IMG_PRODUTO im = bd.IMG_PRODUTO.Find(pr.ID_IMAGEM);
if (im != null && pr.ID_IMAGEM != 0)
{
//Image img = (Image)GridProdutos.Rows[1].Cells[4].FindControl
byte[] byteImagem = im.IMAGEM;
string img64Frente = Convert.ToBase64String(byteImagem);
string imagemDataUrl =
String.Format("data:image/png;base64, {0}", img64Frente);
//img.ImageUrl = imagemDataUrl;
dt.Rows.Add(pr.ID, pr.NOME, pr.VALOR_UNIT, imagemDataUrl);
}
}
GridProdutos.DataSource = dt;
GridProdutos.DataBind();
}
HTML CODE
<asp:GridView ID="GridProdutos" runat="server" AutoGenerateColumns ="false" OnRowCommand ="GridProdutos_RowCommand" AllowPaging="true" OnPageIndexChanging="GridProdutos_PageIndexChanging" OnRowDataBound ="GridProdutos_RowDataBound">
<columns>
<asp:BoundField DataField ="id" HeaderText="Index" />
<asp:BoundField DataField ="nome" HeaderText="Nome do Produto" />
<asp:BoundField DataField ="valor_unit" DataFormatString="{0:c}" HeaderText="Valor Unitario" />
<asp:TemplateField>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Width="100" Height="100" />
<asp:Button ID ="btnAdiciona" runat="server" CommandName="AddItem" Text="Add Carrinho" CommandArgument='<%# Bind("id") %>'/>
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
One could put the HTML code that was generated?
– novic
ready, I put the HTML
– Antonio_Sistema_de_Informacao
In the picture1 did not fail to pass the command to load the information. ?
– novic
Test there
<asp:Image ID="Image1" runat="server" Width="100" Height="100" ImageUrl='<%# Bind("imagem1") %>' />
– novic
Yes, it gave kkkk, you can explain to me how you solved it ?
– Antonio_Sistema_de_Informacao
I looked at your code and was missing pass the information to the controller to load ... if you made the correct code, but at the time of calling on the screen did not pass the variable to load the items! if blz worked!
– novic