我正在c#中使用HTML。我如何在一段时间内为每个循环创建新的div,以便能够根据需要创建指定人
我的html代码:
df4 = pd.concat([df21, df31])
df = df4.reindex(index=df1.index.intersection(df4.index), columns=df1.columns)
我的C#代码:
< 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
我需要帮助
答案 0 :(得分:0)
稍作搜索,就可以找到很多解决此问题的样本
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);
}
然后,您可能需要注意事件,因为它是在其中生成控件的
答案 1 :(得分:0)
您可以使用文本模板作为其中一种方法。
例如尝试https://github.com/jehugaleahsa/mustache-sharp。只需创建HTML模板并使用{{#each}}
标签进行循环即可。
将来,您可以更轻松地更改模板,对我而言,进行标记更容易