Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs EventArgs)
If Not Me.IsPostBackThen
BindRepeater()
End If
End Sub
Private Sub BindRepeater()
Dim conStringAs String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim queryAs String ="SELECT * FROM tblFiles WHERE ContentType = ''image/jpeg''"
Dim cmdAs SqlCommand =New SqlCommand(query)
Using conAs SqlConnection =New SqlConnection(conString)
Using sdaAs SqlDataAdapter =New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dtAs 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 senderAs Object,ByVal eAs RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.ItemOrElse e.Item.ItemType = ListItemType.AlternatingItemThen
Dim bytesAs Byte() =CType((TryCast(e.Item.DataItem, DataRowView)).Row("Data"),Byte())
Dim base64StringAs String = Convert.ToBase64String(bytes, 0, bytes.Length)
TryCast(e.Item.FindControl("ibImage"), ImageButton).ImageUrl ="data:image/png;base64," & base64String
End If
End Sub
Protected iAs Integer = 0
Protected Sub Repeater1_ItemDataBound(ByVal senderAs Object,ByVal eAs RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.SeparatorThen
If (System.Threading.Interlocked.Increment(i)Mod 2) <> 0Then
e.Item.Visible =False
End If
End If
If e.Item.ItemType = ListItemType.ItemOrElse e.Item.ItemType = ListItemType.AlternatingItemThen
Dim bytesAs Byte() =CType((TryCast(e.Item.DataItem, DataRowView)).Row("Data"),Byte())
Dim base64StringAs String = Convert.ToBase64String(bytes, 0, bytes.Length)
TryCast(e.Item.FindControl("ibImage"), ImageButton).ImageUrl ="data:image/png;base64," & base64String
End If
End Sub