就是  留言的 删除回复功能问题,我想这样做   判断管理员是否登录   如果管理员登录了   删除和回复按键 才能显示出来   如果管理员未登录  者普通的访问留言板 是看不到  删除和回复按键的   我弄了好几次都弄不对.....错误提示:
编译错误 
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 编译器错误信息: CS0117: “index”并不包含“lbtnDelete”的定义源错误: 行 17:         if (Session["admin"] != null)
行 18:         {
行 19:             this.lbtnDelete.Visible=false ;
行 20:         }
行 21:         this.datalist();
代码是这样写的
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin"] != null)
        {
            this.lbtnDelete.Visible=false ;
        }
        this.datalist();
        
    
    }
    protected void datalist()
    {
        SqlConnection con = DB.createCon();
        con.Open();
        SqlDataAdapter sda=new SqlDataAdapter ();
        sda.SelectCommand = new SqlCommand("select * from lyb order by uid desc", con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "liu");
        this.DataList1.DataSource = ds.Tables["liu"];
        this.DataList1.DataBind();
    }
    
    protected void lbtnReply_Command1(object sender, CommandEventArgs e)
    {
        if (Session["admin"] != null)
        {
            string userID = e.CommandArgument.ToString();
            Response.Redirect("reply.aspx?userID=" + userID + "");
        }
        else
        {
            Response.Write("<script>alert('对不起,只有管理员才允许回复留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
        }
    }
    protected void lbtnDelete_Command(object sender, CommandEventArgs e)
    {
        if (Session["admin"] != null)
        {
            //string userID = e.CommandArgument.ToString();
            string userID = e.CommandArgument.ToString();
            SqlConnection con = DB.createCon();
            con.Open();
            SqlCommand cmd = new SqlCommand("delete from lyb where uid='" + userID + "'", con);
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Write("<script>alert('对不起,只有管理员才允许删除留言,如果你是管理员,请先登陆!');window.location.href='login.aspx';</script>");
            Response.Write("<script>alert('删除成功!');window.location=window.location;</script>");
        }
            }
}

忘前辈 指教!谢谢啦
 

解决方案 »

  1.   

    管理员登陆 后有session  或者 cookie 
    你判断页面的 session身份是否为  管理员 是就 his.lbtnDelete.Visible=true;
    不是就his.lbtnDelete.Visible=false ; 
      

  2.   

    Session["admin"] != null 这是一个判断语句  因为之前你没有给Session["admin"] 赋值 所以会index错误 系统管理员的登录ID 在用户权限这一块通常用的是Session 在用户登录的时候存储 
    Session["admin"] =账户ID
    那么这时候你可以判断Session["admin"]是否等于管理员ID。
      如果可能拥有这个权限的账户不唯一 也可以在登录的时候 查询其是否属于管理员的角色 有 就在Session里存储个值  用到以后的权限判断  怎么设定就看你怎么去设计系统权限了 
      

  3.   

    ilbtnDelete在那里定义的
    this.lbtnDelete.Visible=Session["admin"] == null?false:true;
    datalist可使用Visible="<%# GetVisible() %>获取
    public bool GetVisible()
    {
     return Session["admin"] == null?false:true;
    }或findcontrol查找控件设置visible
      

  4.   

    if (Session["admin"] != null)
    {
    this.lbtnDelete.Visible=false ;
    }
    貌似你弄反了,你不是要管理员登录就显示么,怎么false了
      

  5.   

    this.lbtnDelete你的这个按扭是不是定义在Repeater控件或是GridView里的?
    如果是这样的话,你是不能这样用的。