aspx页代码:
<asp:Repeater ID="rptBlog" runat="server" DataSourceID="objBlog" OnItemDataBound="rptBlog_ItemDataBind"> <ItemTemplate> <div id="rptBlogTitle"> <h3> <a> <%#eval_r( "blogTitle") %> </a> </h3> ( <%#eval_r( "blogDate") %> ) </div> <div id="divBlogEditDel" runat="server" visible="false"> <a href="EditBlog.aspx"> [编辑] </a> <a href="#"> [删除] </a> </div> <div id="rptBlogTypeName"> </div> <div id="rptBlogContent"> <%#eval_r( "blogContent") %> </div> <div id="rptBlogFooter"> <a href="blogContent.aspx"> 查看全文 </a> </div> </ItemTemplate> </asp:Repeater>
后台代码:
protected void rptBlog_ItemDataBind(object sender, RepeaterItemEventArgs e) { if (Session["UserName"] != null) { if (Session["UserName"].ToString() == this.bc_UserName.GetBlog_UserName()) { e.Item.FindControl("divBlogEditDel").Visible = true; } } }