C# 如何为C中的每个循环创建新的div#
我将HTML与c#结合使用。如何在while中为每个循环创建新的div,以使指定人员符合我的要求 我的html代码:C# 如何为C中的每个循环创建新的div#,c#,html,C#,Html,我将HTML与c#结合使用。如何在while中为每个循环创建新的div,以使指定人员符合我的要求 我的html代码: < div class="col-lg-4 col-md-4 col-sm-6 col-xs-12"> <div class="blog-post2"> <div class="post-img"><a href = "#" >< img src="images/blog-img16.jpg"
< div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="blog-post2">
<div class="post-img"><a href = "#" >< img src="images/blog-img16.jpg" alt=" "></a></div>
<div class="post-text">
<div class="date">
<span class="post-date">26</span>
<span class="month">Oct<br>2017</span>
</div>
<h4><a href = "#" > Title </a></h4>
<p>Detelse</p>
<a href = "#" class="read-more">detelse</a>
</div></div>
</div>
我想根据查询结果为我的新闻创建一个div
我需要帮助通过谷歌搜索,你可以找到很多关于这个问题的示例
foreach (var item_1 in row2.ItemArray)
{
HtmlGenericControl myDiv = new HtmlGenericControl("div");
myDiv.Attributes.Add("class", "col-lg-4 col-md-4 col-sm-6 col-xs-12");
/*
You need to do same thing for every div you have inside
the parent div, and simply add them to parent div and
finally add your parent div to a Panel or Page or
any other place holder you have
*/
myPanel.Controls.Add(myDiv);
}
然后,您可能需要注意事件,在事件中生成控件您可以使用文本模板作为其中一种方法 举个例子。只需创建HTML模板并对循环使用
{{{#each}}
标记
在未来,您可以更轻松地更改模板,而我可以更轻松地使用Asp或创建Html文本进行标记?对于Asp,可以是一个转发器,也可以通过编程将Asp组件添加到面板中,或者类似razor的东西。如果是像电子邮件内容等Html文本,Razor是目前最简单的解决方案。每个解决方案都可以在一个2页的教程中演示。当您提到一个面板时,我将添加
asp:Panel
生成一个div,以便您可以直接使用它的样式。
foreach (var item_1 in row2.ItemArray)
{
HtmlGenericControl myDiv = new HtmlGenericControl("div");
myDiv.Attributes.Add("class", "col-lg-4 col-md-4 col-sm-6 col-xs-12");
/*
You need to do same thing for every div you have inside
the parent div, and simply add them to parent div and
finally add your parent div to a Panel or Page or
any other place holder you have
*/
myPanel.Controls.Add(myDiv);
}