在我的網站中,我有2張表 - 專輯和圖像。如何在運行時在C#中添加<span>標籤
album contains aid,alname。同樣圖像包含 - imgid,imgname, imgurl,imgdes和aid [外鍵]。
這是我的gallery.aspx頁:
<body style="background-image:url('Images/Backgrounds/back.jpg')">
<form id="form1" runat="server">
<h1 style="color:White"><i>Gallery - Albums</i></h1>
<div id="container" runat="server" style="border-style:ridge; border-color:dimgrey; height:565px; padding-left:50px;padding-right:30px;padding-top:20px;padding-bottom:20px;"></div>
</form>
</body>
,這是我的代碼隱藏:在圖像按鈕
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
con.Open();
com = new SqlCommand("select * from album", con);
reader = com.ExecuteReader();
DataTable dtnew = new DataTable();
dtnew.Load(reader);
DataTable[] dt = new DataTable[6];
con.Close();
if (dtnew.Rows.Count > 0)
{
for (int i = 0; i < dtnew.Rows.Count; i++)
{
con.Open();
int id = Convert.ToInt32(dtnew.Rows[i]["aid"]);
DataTable dttemp = new DataTable();
SqlCommand com1 = new SqlCommand("select * from image where aid=" + id + " ORDER BY aid desc", con);
SqlDataReader dr = com1.ExecuteReader();
dttemp.Load(dr);
dt[i] = dttemp;
ImageButton img = new ImageButton();
img.ImageUrl = Convert.ToString(dt[i].Rows[0]["imgurl"]);
img.ID = Convert.ToString(dtnew.Rows[i]["aid"]);
img.Click += new ImageClickEventHandler(Img1_Click);
img.AlternateText = Convert.ToString(dtnew.Rows[i]["alname"]);
img.ToolTip = Convert.ToString(dtnew.Rows[i]["alname"]);
img.CssClass = "galimg";
con.Close();
container.Controls.Add(img);
}
}
此代碼僅加載1圖像並將其顯示爲相冊,當點擊時,它將加載另一個頁面,其中所有與該相冊有關的圖像。
這是現在的樣子:
我現在想的是我絕對要非常久遠的循環每個ImageButton的添加SPAN或DIV的部分。所以這個圖像按鈕將有一些背景的寬度和高度大於圖像按鈕..我怎麼能做到這一點。
我該如何在運行時做到這一點?
給我一秒鐘.. I'l嘗試.. 。:) –
哇兄弟...作品完美...正如所料...非常感謝... :) +1 –
非常歡迎:) – Darren