<asp:Repeater ID="repNewsComment" runat="server">
<ItemTemplate>
<div id="newscomment" style="margin-bottom: 20px; text-align: left;">
<p class="commentbackcolor">
<span> 路保安</span> <span><%#Eval("createTime").ToString().Substring(0, Eval("createTime").ToString().LastIndexOf(":"))%></span>
<asp:LinkButton ID="lbtnDeleteComment" CausesValidation="false" CommandArgument='<%#Eval("id") %>' runat="server" OnClick="lbtnDeleteComment_Click" OnClientClick="return confirm('是否要真的删除该评论?')">删除</asp:LinkButton>
</p>
<p style="padding-left: 7px;">
<%#Eval("content") %>
</p>
</div>
</ItemTemplate>
</asp:Repeater>
c#
#region 删除新闻评论 /// <summary> /// 删除新闻评论 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lbtnDeleteComment_Click(object sender, EventArgs e) { //TODO:repeater中实现删除 比较麻烦的 //当前点击按钮 LinkButton lb = (LinkButton)sender; //获取传过来的commwntid string comId = lb.CommandArgument; //Response.Write(comId); //删除该评论 bool b = new NewsCommentManager().Delete(comId); if (b) { //重新绑定新闻评论 string newsid = Request.QueryString["newsid"]; BindComment(newsid); } else { Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('评论删除失败,请联系管理员!');</script>"); } } #endregion #region 绑定新闻评论 /// <summary> /// 绑定新闻评论 /// </summary> /// <param name="newsid">新闻id</param> private void BindComment(string newsid) { DataTable dt = new NewsCommentManager().SelectByNewsId(newsid); if (dt.Rows.Count == 0) { NoneComment.Visible = true; } else { NoneComment.Visible = false; repNewsComment.DataSource = dt; repNewsComment.DataBind(); } } #endregion