简体   繁体   English

如何在ASPX中动态呈现HTML而无需在ASPX代码中的C#代码或C#代码中嵌入HTML?

[英]How to dynamically render HTML in ASPX without embedding HTML in C# code or C# code in ASPX code?

I'm trying to loop through a data set on the server-side (not a problem) and dynamically render HTML based on the items in the dataset (super basic stuff). 我试图在服务器端循环一个数据集(不是问题),并根据数据集中的项目动态呈现HTML(超级基本的东西)。 Here's the simplified HTML: 这是简化的HTML:

<div>item title</div>
<div>item date</div>
<div>item summary</div>

I have 10 items being returned on the back-end, so I'd like to write out 10 iterations of the HTML above. 我在后端返回了10个项目,所以我想写出上面10个HTML的迭代。 I know this is super basic stuff, but I'd like to do this in ASP.NET without 1) embedding HTML in the C# code 2) embedding C# in the ASPX code 我知道这是超级基本的东西,但是我想在ASP.NET中这样做,而不是1)在C#代码中嵌入HTML 2)在ASPX代码中嵌入C#

Is this possible? 这可能吗? What's the best way to do this? 最好的方法是什么? I'm also not using MVC, so please keep that in mind. 我也没有使用MVC,所以请记住这一点。 Thank you. 谢谢。

I would consider using a Repeater for this 我会考虑使用Repeater

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater(v=vs.110).aspx

It's a control designed for repeating arbitrary html based on the content of a data source 它是一个控件,用于根据数据源的内容重复任意html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM