我想 GridView 或 FormView 中的 “编辑、删除”按钮在页面登录后才显示出来,该怎么做?

解决方案 »

  1.   

    在前台设置一个登录的标识,让这两个按钮的Visible绑定在此标示上即可后台    private bool isAdmin = false;    public bool IsAdmin
        {
            get { return isAdmin; }
        }    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserName"] != null)
            {
                isAdmin = (Session["UserName"].ToString().ToLower() == "admin");
            }
        }前台
    <asp:GridView ID=...>
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button id="btnEditCategory" Visible="<%# IsAdmin %>" Runat="server" CommandName="Edit" ></asp:Button>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>