I have created a sample using the article
Display Images in GridView Control using the path stored in SQL Server database
To the table I have added a new field to store the Views and when Image in GridView is clicked, it will be redirected to another page where Views of the Image will be updated.
Default.aspx
HTML
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />
<hr />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" HeaderStyle-BackColor="#3AC0F2"
HeaderStyle-ForeColor="White">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="FileName" HeaderText="Image Name" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:HyperLink NavigateUrl='<%# Eval("ID", "~/Image.aspx?id={0}") %>' runat="server">
<asp:Image ImageUrl='<%# Eval("FilePath") %>' runat="server" Width="215" Height="150" />
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
Code
protected void Page_Load(object sender, EventArgs e)
{
string conStr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
string query = "SELECT * FROM tblFiles ORDER BY Id";
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlConnection con = new SqlConnection(conStr))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
DataTable dt = new DataTable();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
protected void Upload(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/images/" + fileName));
string query = "INSERT INTO tblFiles(FileName, FilePath) VALUES(@FileName, @FilePath)";
string conStr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Parameters.AddWithValue("@FileName", fileName);
cmd.Parameters.AddWithValue("@FilePath", string.Format("images/{0}", fileName));
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
SQL
ALTER TABLE [dbo].[tblFiles] ADD [Views] INT NULL
Screenshot

Image.aspx
HTML
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
FileName
</td>
<td>
<asp:Label ID="lblFileName" runat="server" />
</td>
</tr>
<tr>
<td>
Views
</td>
<td>
<asp:Label ID="lblViews" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image1" runat="server" Width="215" Height="150" />
</td>
<td>
</td>
</tr>
</table>
<br />
<asp:Button runat="server" OnClick="Back" Text="Back" />
Namespaces
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Code
protected void Page_Load(object sender, EventArgs e)
{
string conStr = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
using (SqlConnection con = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand("GetImage", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Id", int.Parse(Request.QueryString["Id"]));
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr.Read())
{
this.lblFileName.Text = sdr["FileName"].ToString();
this.lblViews.Text = sdr["Views"].ToString();
this.Image1.ImageUrl = sdr["FilePath"].ToString();
}
}
con.Close();
}
}
}
protected void Back(object sender, EventArgs e)
{
Response.Redirect("~/CS.aspx");
}
SQL
CREATE PROCEDURE [GetImage]
@Id INT
AS
BEGIN
SET NOCOUNT ON;
UPDATE tblFiles
Set Views = ISNULL(Views, 0) + 1
WHERE ID = @Id
SELECT * FROM tblFiles WHERE ID = @Id
END
GO
Screenshot