Protected
Sub
Page_Load(
ByVal
sender
As
Object
,
ByVal
e
As
EventArgs)
If
Not
Me
.IsPostBack
Then
BindRepeater()
End
If
End
Sub
Private
Sub
BindRepeater()
Dim
conString
As
String
= ConfigurationManager.ConnectionStrings(
"constr"
).ConnectionString
Dim
query
As
String
=
"SELECT * FROM tblFiles WHERE ContentType = ''image/jpeg''"
Dim
cmd
As
SqlCommand =
New
SqlCommand(query)
Using con
As
SqlConnection =
New
SqlConnection(conString)
Using sda
As
SqlDataAdapter =
New
SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt
As
DataTable =
New
DataTable()
sda.Fill(dt)
rptImages.DataSource = dt
rptImages.DataBind()
Repeater1.DataSource = dt
Repeater1.DataBind()
End
Using
End
Using
End
Using
End
Sub
Protected
Sub
rptImages_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
RepeaterItemEventArgs)
If
e.Item.ItemType = ListItemType.Item
OrElse
e.Item.ItemType = ListItemType.AlternatingItem
Then
Dim
bytes
As
Byte
() =
CType
((TryCast(e.Item.DataItem, DataRowView)).Row(
"Data"
),
Byte
())
Dim
base64String
As
String
= Convert.ToBase64String(bytes, 0, bytes.Length)
TryCast(e.Item.FindControl(
"ibImage"
), ImageButton).ImageUrl =
"data:image/png;base64,"
& base64String
End
If
End
Sub
Protected
i
As
Integer
= 0
Protected
Sub
Repeater1_ItemDataBound(
ByVal
sender
As
Object
,
ByVal
e
As
RepeaterItemEventArgs)
If
e.Item.ItemType = ListItemType.Separator
Then
If
(System.Threading.Interlocked.Increment(i)
Mod
2) <> 0
Then
e.Item.Visible =
False
End
If
End
If
If
e.Item.ItemType = ListItemType.Item
OrElse
e.Item.ItemType = ListItemType.AlternatingItem
Then
Dim
bytes
As
Byte
() =
CType
((TryCast(e.Item.DataItem, DataRowView)).Row(
"Data"
),
Byte
())
Dim
base64String
As
String
= Convert.ToBase64String(bytes, 0, bytes.Length)
TryCast(e.Item.FindControl(
"ibImage"
), ImageButton).ImageUrl =
"data:image/png;base64,"
& base64String
End
If
End
Sub