【发布时间】:2017-07-07 00:52:41
【问题描述】:
所以再次需要帮助
抱歉有点混乱,但是我正在尝试创建一个用户可以提交然后从数据库中再次检索它的聊天框,我正在关注这个脚本https://bootsnipp.com/snippets/EkQe7
可以看到,从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>
我的问题是如何从 Code-Behind PageLoad 中做到这一点?如何将上面的代码从代码隐藏添加到中继器中?
谢谢!
【问题讨论】:
-
将
"You"文本包装在<asp:Label>中。将<asp:Literal>放在这些交替代码所在的中继器中。在Repeater的ItemDataBound事件中,确保项目类型为Item或AlternatingItem。使用e.Item.FindControl("YourLiteralID")和e.Item.FindControl("YourLabelID")获取控件。根据YourLabelId.Text的值,用您的 HTML 填充文字。 -
为什么不在前端使用 foreach 而不是 Repeater?
<% foreach (var msg in msgs) { %> <div>...<%= msg.txt %>...</div> <% } %> -
@Santi 感谢您的帮助!但是我还是不太明白,可以给我代码吗?对不起!
-
@chakeda 嗨,我该怎么做?抱歉,我是新手,第一次听说 foreach