日期:2014-05-17 浏览次数:20575 次
<asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound"> <ItemTemplate> <% if (Session["name"].ToString() == Eval("sname").ToString()) { %> <asp:LinkButton Visible="False" Style="margin-left: 10px;" ID="lnkDelete" runat="server" OnClick="Delete">删除</asp:LinkButton> <% } %> </ItemTemplate> </asp:ListView>
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { LinkButton lnkDelete = e.Item.FindControl("lnkDelete") as LinkButton; if (lnkDelete != null) { if (Session["name"] != null && Session["name"].ToString() == DataBinder.Eval(e.Item.DataItem, "sname").ToString()) { lnkDelete.Visible = false; } else { lnkDelete.Visible = true; } } } }