自己动手做博客之日志管理-5.4 管理评论
2007-10-16 13:06
274 查看
评论是单向管理,即只可以添加和删除,即使是管理员也不可以修改对日志的评论。管理评论使用了用户控件ucAdmin_Comment.ascx,运行效果如图15-21所示。
图15-21 管理评论
图15-21所示的效果可以很容易看出,使用Repeater控件会更合适,一个简单的列表,如下所示为布局代码:
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<dl id="postComment" class="list"><div class="topic_r"><a href='Admin_Index.aspx?delComm=<%#DataBinder.Eval(Container.DataItem,"id")%>'>删除</a></div><dt style="cursor:hand;" > <%#DataBinder.Eval(Container.DataItem,"date")%> 署名:<%#DataBinder.Eval(Container.DataItem,"author")%> 在 <%#DataBinder.Eval(Container.DataItem,"IP")%> 说:</dt>
<dd> <%#DataBinder.Eval(Container.DataItem,"content")%> </dd>
</dl>
</ItemTemplate>
</asp:Repeater>
从布局代码中看到“删除”链接的地址为Admin_Index.aspx,指定一个delComm参数值为要删除的评论编号。这个参数在Admin_Index.aspx页面时并未提及,因为它是由评论模块产生的,因此也要在这里处理。如下所示了ucAdmin_Comment用户控件的后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dbconfig dbcon = new dbconfig();
if (Request["delComm"] != null)
{
dbcon.ExecuteNonQuery("delete comment where id=" + Request["delComm"]);
Response.Redirect("Admin_Index.aspx");
}
rep.DataSource = dbcon.CreateSource("select * from comment");
rep.DataBind();
dbcon.Clear();
}
}
从上述Page_Load()方法所示的代码执行过程为,ucAdmin_Comment用户控件在第一次加载时会comment表中的评论数据绑定到rep并显示,如果在加载时检测到有delComm参数,则执行删除评论的操作,最后清除连接。
图15-21 管理评论
图15-21所示的效果可以很容易看出,使用Repeater控件会更合适,一个简单的列表,如下所示为布局代码:
<asp:Repeater ID="rep" runat="server">
<ItemTemplate>
<dl id="postComment" class="list"><div class="topic_r"><a href='Admin_Index.aspx?delComm=<%#DataBinder.Eval(Container.DataItem,"id")%>'>删除</a></div><dt style="cursor:hand;" > <%#DataBinder.Eval(Container.DataItem,"date")%> 署名:<%#DataBinder.Eval(Container.DataItem,"author")%> 在 <%#DataBinder.Eval(Container.DataItem,"IP")%> 说:</dt>
<dd> <%#DataBinder.Eval(Container.DataItem,"content")%> </dd>
</dl>
</ItemTemplate>
</asp:Repeater>
从布局代码中看到“删除”链接的地址为Admin_Index.aspx,指定一个delComm参数值为要删除的评论编号。这个参数在Admin_Index.aspx页面时并未提及,因为它是由评论模块产生的,因此也要在这里处理。如下所示了ucAdmin_Comment用户控件的后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dbconfig dbcon = new dbconfig();
if (Request["delComm"] != null)
{
dbcon.ExecuteNonQuery("delete comment where id=" + Request["delComm"]);
Response.Redirect("Admin_Index.aspx");
}
rep.DataSource = dbcon.CreateSource("select * from comment");
rep.DataBind();
dbcon.Clear();
}
}
从上述Page_Load()方法所示的代码执行过程为,ucAdmin_Comment用户控件在第一次加载时会comment表中的评论数据绑定到rep并显示,如果在加载时检测到有delComm参数,则执行删除评论的操作,最后清除连接。
相关文章推荐
- 自己动手做博客之日志管理-5.1 管理员登录
- 自己动手做博客之日志管理-1.1 系统分析
- 自己动手做博客之日志管理-2.2 模板页
- 自己动手做博客之日志管理-5.2 管理日志分类
- 自己动手做博客之日志管理-1.2 数据库分析
- 自己动手做博客之日志管理-3.1 添加系统首页布局
- 自己动手做博客之日志管理-5.3 管理日志列表
- 自己动手做博客之日志管理-3.2 编码实现系统首页
- 自己动手做博客之日志管理-4.1 查看日志列表
- 自己动手做博客之日志管理-5.5 修改密码
- 自己动手做博客之日志管理-2.1 数据库类
- 自己动手做博客之日志管理-3.3 编码实现其他模块
- 自己动手做博客之日志管理-4.2 查看日志正文
- [新功能]在管理页面查看自己发表过的评论
- 一步步搭建自己的博客 .NET版(2、评论功能)
- CSDN 如何搜索自己的博客 怎么查看我评论过的帖子
- github+hexo搭建自己的博客网站(五)进阶配置(畅言实现博客的评论)
- 这些年收藏的技术大牛博客分享(后续还会继续更新)大家可以在评论中分享自己关注的
- 要好好管理自己的博客,用来备忘,做计划,以便朋友监督
- 自己开发的日志管理系统