On my page i have a Gridview fildet over SQl Auto witout Template Filds. All setting are code behind. ondatabound
Now i have a Base64 String in the sql table and gridview dont schow image. i see the base64string in the result.
How i can convert the string to image in code behind section witout TemplateFilds in aspx. Templatefild is not able Gridview is dinamicel over multible combination of databases. Just the firs 2 columns are staic.
ASPX
<asp:GridView ID="mergeresult" runat="server" BackColor="LightGoldenrodYellow" BorderColor="Tan" OnRowCreated="mergeresult_OnRowCreated"
OnRowDataBound="mergeresult_OnRowDataBound" BorderWidth="1px" CellPadding="2"
ForeColor="Black" GridLines="Both" autogeneratedcolumns=false>
<AlternatingRowStyle BackColor="PaleGoldenrod" />
<FooterStyle BackColor="Tan" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<SortedAscendingCellStyle BackColor="#FAFAE7" />
<SortedAscendingHeaderStyle BackColor="#DAC09E" />
<SortedDescendingCellStyle BackColor="#E1DB9C" />
<SortedDescendingHeaderStyle BackColor="#C2A47B" />
<HeaderStyle Font-Size="Small" Font-Underline="true" />
<RowStyle Font-Size="12px" />
</asp:GridView>
C#
protected void mergeresult_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex >= 0)
{
int totalRow = mergeresult.Rows.Count;
int totalColumns = mergeresult.Columns.Count;
for (int i = 0; i < totalRow 1; i )
{
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
// Image Converting ?? Field e.Row.Cells[1] have the base64 string inside.
}
}
}
}
DataBind
protected void run_Click(object sender, EventArgs e)
{
// Dynamicel results from SQL Databases
mergeresult.DataSource = dt1;
mergeresult.DataBind();
}
CodePudding user response:
manipulate your SQL so the output is like below, How to display Base64 images in HTML
<div>
<p>Taken from wikpedia</p>
<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
</div>
CodePudding user response:
Danks JobesK for your answer and the way for solution.
i have solved and use the code.
c#
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Length >= 500)
{
// string data = "";
String TagStart1 = "";
String Coding = "";
String TagEnd = "";
string Combi = "";
String Dimension = "";
string AltText = "";
//data = cell.Text.ToString();
TagStart1 = "<img src=";
Coding = "data:image/jpg;base64,";
TagEnd = "\"";
Combi = TagStart1 TagEnd Coding e.Row.Cells[1].Text TagEnd;
Dimension = " width=\"65px\" height=\"65px\">";
AltText = " alt=\"testing\""; // "alt=\"" e.Row.Cells[4].ToString() "\"";
e.Row.Cells[1].Text = Combi AltText Dimension;
e.Row.Cells[1].HorizontalAlign = HorizontalAlign.Center;
}
else
{
e.Row.Cells[1].Text = "Kein Bild";
}
}
Have you a ide to put the images in Original Format from base64 into a Tag with Format resizing.