Hi RichardSa,
Check this example. Now please take its reference and correct your code.
Database
CREATE TABLE [tblFilePath]
(
[Id] [int] NULL,
[ImageName] [varchar](max) NULL,
[Path] [nvarchar](max) NULL
)
GO
INSERT INTO [tblFilePath] VALUES (1,'acct.jpg','Images/acct.jpg')
HTML
<div>
<div class="parent">
<div class="child" id="midcont" runat="server">
<br />
<div class="company-address">
<p style="font-size: 9pt;">CUSTOMER:</p>
<asp:TextBox ID="TextBox2" runat="server" CssClass="form-control" TextMode="MultiLine" Placeholder="CUSTOMER NAME"
Height="40px" Font-Size="X-Small" Width="240px" BorderStyle="Solid" BorderWidth="2"></asp:TextBox>
<br />
<br />
<asp:TextBox ID="ftxtaddress" runat="server" CssClass="form-control" TextMode="MultiLine" Placeholder="CUSTOMER ADDRESS"
Height="40px" Font-Size="X-Small" Width="240px" BorderStyle="Solid" BorderWidth="2"></asp:TextBox>
<br />
<asp:TextBox ID="ftxtmail" runat="server" CssClass="form-control" Font-Size="X-Small" placeholder="CUSTOMER EMAIL"
Height="25px" Width="240px" BorderStyle="Solid" BorderWidth="2"></asp:TextBox>
<br />
<asp:TextBox ID="ftxtphone" runat="server" CssClass="form-control" placeholder="CUSTOMER PHONE N°"
Font-Size="X-Small" Height="25px" Width="240px" BorderStyle="Solid" BorderWidth="2" />
</div>
</div>
</div>
</div>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
midcont.Attributes.Add("style",
string.Format("width: 100%; background: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,.5)), url('{0}') no-repeat;", GetImagePath()));
}
}
private string GetImagePath()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string imagePath = string.Empty;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 [Path] FROM [tblFilePath]", con))
{
con.Open();
imagePath = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
}
return imagePath;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
midcont.Attributes.Add("style",
String.Format("width: 100%; background: linear-gradient(rgba(255,255,255,.5), rgba(255,255,255,.5)), url('{0}') no-repeat;", GetImagePath()))
End If
End Sub
Private Function GetImagePath() As String
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim imagePath As String = String.Empty
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand("SELECT TOP 1 [Path] FROM [tblFilePath]", con)
con.Open()
imagePath = Convert.ToString(cmd.ExecuteScalar())
con.Close()
End Using
End Using
Return imagePath
End Function
Screenshot