我正在 ASP.NET Web 表单中开发一个简单的留言板,并在 ListView 控制器中列出所有帖子。我的代码看起来像这样:
<ItemTemplate>
<article class="post">
<div class="postinfo">
<div class="postauthor">
Author: <strong><%# Eval("Author") %></strong>
</div>
<div class="postdate">
Date: <strong><%# Eval("PostDate", "{0:D}") %></strong>
</div>
<div class="postvotes">
<asp:Button class="postupvote" id='up<%# Eval("Id") %>' runat="server" />
<asp:Label ID="postvotescount_<%# Eval("Id") %>" class="postvotescount" runat="server" Text="<%# Eval("Votes") %> votes"></asp:Label>
<asp:Button class="postdownvote" id='down<%# Eval("Id") %>' runat="server" />
</div>
</div>
<div class="postcontent"><%# Eval("Text") %></div>
</article>
</ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
我的问题是投票功能。我想要有 css id 属性,包含帖子的唯一数据库 id。这样我就能知道该帖子的 ID,它已被投票。那么这可能吗?如果不可能,我该如何实现这一目标?
谢谢!