我試圖從asp.net
代碼隱藏中將幾個<img>
標記添加到我的html文檔中。我看着Adding Html from Code Behind in Asp.net,它似乎是解決方案,但我不知道divcontrol.Controls.Add
如何確定它將開始添加html。據我所知,它是在HTML的末尾。我還發現Write Html Markup from code behind in asp.net,但我不確定如何使用它。修改並從asp.net添加html
所以這裏是我使用的html
。我怎麼可以添加img
標籤我還包括?:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Gallery</title>
<script type='text/javascript' src='/jquery-11.0.min.js'></script>
<script type='text/javascript' src='theme-tiles.js'></script>
</head>
<body>
<form id="form1" runat="server">
<h2>Tiles - Justified</h2>
<div id="gallery" style="display:none;">
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#gallery").gallery({
tiles_type: "justified"
});
});
</script>
</form>
</body>
</html>
這是<img>
標籤,我需要的<div id="gallery">
標籤之間添加:
<img alt="img1"
src="images/thumbs/tile1.jpg"
data-image="images/big/tile1.jpg"
style="display:none"/>
</a>
這是我會用代碼添加html
:
HtmlGenericControl divcontrol = new HtmlGenericControl();
divcontrol.Attributes["class"] = "sxro sx1co";
divcontrol.TagName = "div";
pnlUserSearch.Controls.Add(divcontrol);
Label question = new Label();
divcontrol.Controls.Add(question); // add to the new div, not to the panel