C#ASP.NET根据数据库中的数据将html代码插入到repeater中
所以需要再次帮助 抱歉有点混乱,但是,我正在尝试创建一个聊天框,用户可以提交它,然后从数据库中再次检索它,我遵循这个脚本C#ASP.NET根据数据库中的数据将html代码插入到repeater中,c#,html,css,asp.net,C#,Html,Css,Asp.net,所以需要再次帮助 抱歉有点混乱,但是,我正在尝试创建一个聊天框,用户可以提交它,然后从数据库中再次检索它,我遵循这个脚本 正如你所看到的,从HTML代码中,有两种类型,一种是当你聊天时,另一种是当其他人聊天时 <div class="chat"> <div class="chat-history"> <ul class="chat-ul"> <li> <div c
正如你所看到的,从HTML代码中,有两种类型,一种是当你聊天时,另一种是当其他人聊天时
<div class="chat">
<div class="chat-history">
<ul class="chat-ul">
<li>
<div class="message-data">
<span class="message-data-name"><i class="fa fa-circle you"></i> You</span>
</div>
<div class="message you-message">
A new client?!?! I would love to help them, but where are we going to find the time?
</div>
</li>
<li class="clearfix">
<div class="message-data align-right">
<span class="message-data-name">Ada, your OperationsAlly</span> <i class="fa fa-circle me"></i>
</div>
<div class="message me-message float-right"> We should take a look at your onboarding and service delivery workflows, for most businesess there are many ways to save time and not compromise quality. </div>
</li>
</ul>
</div> <!-- end chat-history -->
</div> <!-- end chat -->
-
你
新客户?!?!我很想帮助他们,但是我们去哪里找时间呢?
-
艾达,你的行动
我们应该看看您的入职和服务交付工作流程,对于大多数业务来说,有许多方法可以节省时间且不影响质量。
现在,我要做的是从数据库中检索消息,然后代码隐藏,将HTML代码提交到转发器中,
如果是“你”,则将使用此代码
<div class="message-data">
<span class="message-data-name"><i class="fa fa-circle you"></i> You</span>
</div>
<div class="message you-message">
A new client?!?! I would love to help them, but where are we going to find the time?
</div>
<li class="clearfix">
<div class="message-data align-right">
<span class="message-data-name">Ada, your OperationsAlly</span> <i class="fa fa-circle me"></i>
</div>
<div class="message me-message float-right"> We should take a look at your onboarding and service delivery workflows, for most businesess there are many ways to save time and not compromise quality. </div>
</li>
你
新客户?!?!我很想帮助他们,但是我们去哪里找时间呢?
如果是其他人,则将使用此代码
<div class="message-data">
<span class="message-data-name"><i class="fa fa-circle you"></i> You</span>
</div>
<div class="message you-message">
A new client?!?! I would love to help them, but where are we going to find the time?
</div>
<li class="clearfix">
<div class="message-data align-right">
<span class="message-data-name">Ada, your OperationsAlly</span> <i class="fa fa-circle me"></i>
</div>
<div class="message me-message float-right"> We should take a look at your onboarding and service delivery workflows, for most businesess there are many ways to save time and not compromise quality. </div>
</li>
艾达,你的行动
我们应该看看您的入职和服务交付工作流程,对于大多数业务来说,有许多方法可以节省时间且不影响质量。
我的问题是如何从PageLoad后面的代码中实现这一点?如何将上面的代码从代码隐藏添加到中继器中
谢谢 首先,您必须在代码隐藏中检索数据库中的记录。(详见此) 现在我们可以使用Repeater(其中html由作者分隔)来迭代数据。请注意,我假设您的消息数据库是如何构造的
<asp:Repeater id="messages" runat="server">
<ItemTemplate>
<div runat="server" visible='<% (Container.DataItem("author") == "us") %>'>
<li>
<div class="message-data">
<span class="message-data-name"><i class="fa fa-circle you"></i> You</span>
</div>
<div class="message you-message">
<%# Eval("testMessage") %>
</div>
</li>
</div>
<div runat="server" visible='<% (Container.DataItem("author") != "them") %>'>
<li class="clearfix">
<div class="message-data align-right">
<span class="message-data-name"><%# Eval("authorName") %></span> <i class="fa fa-circle me"></i>
</div>
<div class="message me-message float-right">
<%# Eval("testMessage") %>
</div>
</li>
</div>
</ItemTemplate>
</asp:Repeater>
将“You”
文本包装在
中。在中继器中放置一个
,在这些交替代码将要到达的位置。在中继器的ItemDataBound
事件上,确保项目类型为item
或AlternatingItem
。使用e.Item.FindControl(“YourLiteralID”)
和e.Item.FindControl(“YourLabelID”)
获取控件。根据YourLabelId.Text
的值,用HTML填充文本。为什么不在前端使用foreach而不是Repeater<代码>代码>@Santi谢谢你的帮助!但我还是不太明白,能不能给我提供代码?对不起@查克达嗨,我该怎么做?对不起,我是新来的,第一次听说foreachThank非常感谢您只需要对这部分做一些澄清,(Container.DataItem(“author”)==“us”,这意味着我的数据库有一个名为“author”的属性,如果里面的值是“us”,那么当中继器启动时,该特定代码将正确执行?正确!正如我所提到的,此代码未经测试-因此,在实现此功能时,您可能需要克服一些错误。好的!非常感谢。了解很多。如果有帮助,请更新投票/接受,并自由评论其他问题。您好,我收到了此错误消息Canno无法从“Visible”属性的字符串表示形式“”创建类型为“System.Boolean”的对象。您知道这是什么触发的吗?