我有一个 div,它的属性集 runat="server" 及其 ID。我正在尝试将来自 MySQL 数据库的特定 div 的动态背景图像放在行中提到的路径 url 中。现在一切正常,但我不知道如何仅对特定 div 赋予样式影响。目前我只在 div 上定义,结果是在该页面上的所有 div 中获取背景图像。如何在我的代码中定义该 div 类或 ID?
Private Sub coverContent_Init(sender As Object, e As EventArgs) Handles coverContent.Init
Try
Dim css As New HtmlGenericControl()
css.TagName = "style"
css.Attributes.Add("type", "text/css")
Dim imageURL As String = String.Empty
Dim var3 As String
var3 = Request.QueryString("hospitalID")
Dim str As String = "Select hospitalID, coverImage from hospitals where hospitalID='" + var3 + "';"
con.Open()
Dim cmd As New MySqlCommand(str, con)
Dim da As New MySqlDataAdapter(cmd)
Dim dt As New DataTable
da.Fill(dt)
con.Close()
If dt.Rows.Count > 0 Then
generalID.Text = dt.Rows(0)("hospitalID").ToString
imageURL = dt.Rows(0)("coverImage").ToString
End If
con.Close()
css.InnerHtml = (Convert.ToString("div{background-image: url(") & imageURL) + ");}"
Page.Header.Controls.Add(css)
MyBase.OnInit(e)
Catch ex As Exception
Response.Write(ex)
End Try
End Sub