Hi RichardSa,
Refer below sample.
For uploading image file to database please refer below article.
HTML
CS
<asp:Repeater runat="server" ID="reptrImg">
<ItemTemplate>
<div class="col-sm-4 col-md-4">
<div class="thumbnail" style="margin: 0 auto; padding: 10px;">
<asp:ImageButton ID="ImageButton1" CssClass="ImageButton" runat="server"
ImageUrl='<%# "data:image/jpeg;base64," + Convert.ToBase64String((byte[])Eval("Data")) %>'
OnClick="ImageButton_Click" Style="width: 20%; height: auto; margin: 0 auto;
border-radius: 1px; background-size: cover; border: 1px solid #f0f1f2;" />
<asp:Label ID="lblDesc" runat="server" Style="font-weight: 500;" Text='<%# Eval("Name") %>'></asp:Label>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
VB.Net
<asp:Repeater runat="server" ID="reptrImg">
<ItemTemplate>
<div class="col-sm-4 col-md-4">
<div class="thumbnail" style="margin: 0 auto; padding: 10px;">
<asp:ImageButton ID="ImageButton1" CssClass="ImageButton" runat="server"
ImageUrl='<%# "data:image/jpeg;base64," & Convert.ToBase64String(CType(Eval("Data"), Byte())) %>'
OnClick="ImageButton_Click" Style="width: 20%; height: auto; margin: 0 auto;
border-radius: 1px; background-size: cover; border: 1px solid #f0f1f2;" />
<asp:Label ID="lblDesc" runat="server" Style="font-weight: 500;" Text='<%# Eval("Name") %>'></asp:Label>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Details
<asp:Image Class="imgfile" ID="imgfile" runat="server" />
<asp:Label ID="LblDept" runat="server" Text=""></asp:Label>
Namespaces
CS
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Code
CS
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM tblFiles"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
reptrImg.DataSource = dt;
reptrImg.DataBind();
}
}
}
}
}
}
protected void ImageButton_Click(object sender, ImageClickEventArgs e)
{
ImageButton imagebutton = sender as ImageButton;
RepeaterItem item = imagebutton.NamingContainer as RepeaterItem;
string description = (item.FindControl("lblDesc") as Label).Text;
Session["Image"] = imagebutton.ImageUrl;
Session["imgname"] = description;
Response.Redirect("~/Details.aspx");
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT * FROM tblFiles")
Using sda As SqlDataAdapter = New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using dt As DataTable = New DataTable()
sda.Fill(dt)
reptrImg.DataSource = dt
reptrImg.DataBind()
End Using
End Using
End Using
End Using
End If
End Sub
Protected Sub ImageButton_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Dim imagebutton As ImageButton = TryCast(sender, ImageButton)
Dim item As RepeaterItem = TryCast(imagebutton.NamingContainer, RepeaterItem)
Dim description As String = (TryCast(item.FindControl("lblDesc"), Label)).Text
Session("Image") = imagebutton.ImageUrl
Session("imgname") = description
Response.Redirect("~/DetailsVB.aspx")
End Sub
Details.CS
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Image"] != null)
{
imgfile.ImageUrl = Session["Image"].ToString();
}
if (Session["imgname"] != null)
{
LblDept.Text = Session["imgname"].ToString();
}
}
Details.VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Session("Image") IsNot Nothing Then
imgfile.ImageUrl = Session("Image").ToString()
End If
If Session("imgname") IsNot Nothing Then
LblDept.Text = Session("imgname").ToString()
End If
End Sub
Screenshot