Refer the below code if you are getting Byte datafrom database then you need to handel it in ItemDataBound refer the below code for your reference.
HTML
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound" >
<ItemTemplate>
<asp:HiddenField ID="hfData" runat="server" />
<div class="item" id="DvItem" runat="server">
<div class="container-fluid">
<div>
<div class="slider-header fadeInDown-1">
Top Brands</div>
<div class="big-text fadeInDown-1">
Pathanjali's Cow Ghee
</div>
<div class="excerpt fadeInDown-2 hidden-xs">
<span>The power that will<br />become a winner will give.</span>
</div>
<div >
<a href="#" style="background-color:White;color:Red;">Shop Now</a>
</div>
</div>
<!-- /.caption -->
</div>
<!-- /.container-fluid -->
</div>
<br />
<!-- /.item -->
</ItemTemplate>
</asp:Repeater>
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
BindRepeaterusingDataTable();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Files file = (e.Item.DataItem as Files);
Byte[] bytes = file.Data;
string base64 = Convert.ToBase64String(bytes);
string imageURL = string.Format("data:image/gif;base64," + base64 + ");");
HtmlControl DvItem = (e.Item.FindControl("DvItem") as HtmlControl);
DvItem.Style["background-image"] = @"url(" + imageURL + ") no-repeat;";
DvItem.Style["background-repeat"] = @"no-repeat";
}
}
private void BindRepeaterusingDataTable()
{
List<Files> files = new List<Files>();
string constr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("select Name, Data from tblFiles", con))
{
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
files.Add(new Files
{
Name = dt.Rows[i]["Name"].ToString(),
Data = (byte[])dt.Rows[i]["Data"]
});
}
}
Repeater1.DataSource = files;
Repeater1.DataBind();
}
}
public class Files
{
public string Name { get; set; }
public byte[] Data { get; set; }
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindRepeaterusingDataTable()
End If
End Sub
Protected Sub Repeater1_ItemDataBound(sender As Object, e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.AlternatingItem OrElse e.Item.ItemType = ListItemType.Item Then
Dim file As Files = TryCast(e.Item.DataItem, Files)
Dim bytes As [Byte]() = file.Data
Dim base64 As String = Convert.ToBase64String(bytes)
Dim imageURL As String = String.Format((Convert.ToString("data:image/gif;base64,") & base64) + ");")
Dim DvItem As HtmlControl = TryCast(e.Item.FindControl("DvItem"), HtmlControl)
DvItem.Style("background-image") = (Convert.ToString("url(") & imageURL) + ") no-repeat;"
DvItem.Style("background-repeat") = "no-repeat"
End If
End Sub
Private Sub BindRepeaterusingDataTable()
Dim files As New List(Of Files)()
Dim constr As String = ConfigurationManager.ConnectionStrings("ConStr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("select Name, Data from tblFiles", con)
Dim sda As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
sda.Fill(dt)
For i As Integer = 0 To dt.Rows.Count - 1
files.Add(New Files() With { _
Key .Name = dt.Rows(i)("Name").ToString(), _
Key .Data = DirectCast(dt.Rows(i)("Data"), Byte()) _
})
Next
End Using
Repeater1.DataSource = files
Repeater1.DataBind()
End Using
End Sub
Public Class Files
Public Property Name() As String
Get
Return m_Name
End Get
Set
m_Name = Value
End Set
End Property
Private m_Name As String
Public Property Data() As Byte()
Get
Return m_Data
End Get
Set
m_Data = Value
End Set
End Property
Private m_Data As Byte()
End Class
Output
