动态添加< p>在asp.net中标记评论系统 [英] dynamically add <p> tag in asp.net for comment system
问题描述
我正在为我的网页添加一个评论框, 我设计了表单来接受用户名和注释,并将其存储在数据库表中.我不知道如何在页面上呈现该数据.在表上进行迭代,然后在页面上创建段落,或者在页面上创建标签.
I am making a comment box for my webpage, I have designed the form to take the user Name and comments and store it in the database table. I don't know how to render that data on the page. Either by iterating on the table and subsequently creating paragraph on the page or by creating labels on the page.
我在C#中使用LINQ to SQL. 请告诉我如何在网页上的数据库或教程的某些链接中呈现注释.
I am using LINQ to SQL in C#. Please tell me how to render the comments in database on web page or some link to tutorial
推荐答案
让我们假设您有一个CommentsTable
具有列:
let's assume you have a CommentsTable
having columns:
- id int
- 用户名varchar(50)
- 评论nvarchar(5000)
- DateCreated DateTime
并且您的LinqToSql数据上下文是myDataContext,您可以执行以下操作:
and your LinqToSql data context is myDataContext thn you can do this:
myDataContext db = new myDataContext();
var commentsData = db.CommentsTable.ToList();
string html=string.Empty;
foreach(var item in commentsData)
{
html+="<div class='property-row'><div class='username'>"+item.Username+"</div>";
html+="<div class='notice'>"+item.DateCreated.ToString("mm-dd-yyyy hh:mm")+"</div>"
html+="<div class='comment'>"+item.Comment+"</div>";
}
Div1.InnerHtml= html;
现在,您可以通过适当装饰设计器中的类来控制部分的外观,即用户名行及其下方的注释 即
now you can control look of your sections i.e. username row and the comments beneath it by suitably decorating the classes on the designer i.e.
.property-row
{
position:relative;
width:100%;
background-color:#CCCCCC;
border:1px solid Black;
}
.username
{
position:relative:
padding:2px;
top:2px;
font-size:0.8em;
color:#333333;
text-decoration:underline;
}
.comment
{
position:relative;
padding:2px;
margin:2px;
font-size:1em;
color:black;
}
.notice
{
font-size:0.7em;
}
这篇关于动态添加< p>在asp.net中标记评论系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!