Hi varun3752,
Check this example. Now please take its reference and correct your code.
HTML
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<asp:PlaceHolder runat="server" ID="PlaceHolder1" />
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
//Populating a DataTable from database.
DataTable dt = this.GetData();
//Building an HTML string.
StringBuilder html = new StringBuilder();
//Table start.
html.Append("<table class='table table-responsive'>");
//Building the Header row.
html.Append("<tr>");
foreach (DataColumn column in dt.Columns)
{
html.Append("<th>");
html.Append(column.ColumnName);
html.Append("</th>");
}
html.Append("</tr>");
//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
html.Append("<tr>");
html.Append("<td>");
html.Append(row["id"]);
html.Append("</td>");
html.Append("<td>");
html.Append(row["Name"]);
html.Append("</td>");
html.Append("<td>");
html.Append(row["ContentType"]);
html.Append("</td>");
html.Append("<td>");
html.Append("<img height='75px' width='75px' src=\'data:image/jpg;base64," + Convert.ToBase64String((byte[])row["Data"]) + "' />");
html.Append("</td>");
html.Append("</tr>");
}
//Table end.
html.Append("</table>");
//Append the HTML string to Placeholder.
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
}
}
private DataTable GetData()
{
string conString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT Id,Name,ContentType,Data FROM tblFiles WHERE ContentType = 'image/jpeg'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
Screenshot
![](https://i.imgur.com/VNAtIje.jpg)