1.DataBase.DBFactory   clsDbFac   =   new   DataBase.DBFactory(); 这个不要这样声明,WEB不同C/S模式,不然你点删除时,肯定会出错的.把它放到各个方法里,不要声明为整个类的.2.string   st   =   clsDbFac.ExecuteSqlScalar(sql1); //?你这里是什么意思?这个方法返回的应该是结果里的第一行第一列的"值",而不是行数
                int   intReturn   =   Convert.ToInt32(st); //同上
                if   (intReturn   >   0) //我估计你的这个条件块都没运行
                { 
                      DataBind(); 
                } 
  if   (!Page.IsPostBack) //这里说明是第一次加载页面时运行的,但看了一下你数据绑定的方法,有错误
                { 
                        DataBind(); 
                        
                } 
//重写绑定方法 
        public   override   void   DataBind() 
        { 
                string   sql2   =   "select   *   from   [USER]   where   USERNAME='"   +   this.txtUserName.Text   +   "'";   ; //????你的这个文本框是哪来的,如果你的网页第一次加载时,肯定取不到数据的,人家根本就没有在文本框里输入值(还没打开怎么输入?)
                DataTable   dt   =   clsDbFac.ExecuteSqlDataTable(sql2); 
                this.gdvUser.DataSource   =   dt; 
                this.gdvUser.DataKeyNames   =   new   string[]   {   "USERID"   }; 
                this.gdvUser.DataBind(); 
        } 

解决方案 »

  1.   

    1. DataBase.DBFactory   clsDbFac   =   new   DataBase.DBFactory();  這個放在 
            public   override   void   DataBind()
            {
                 DataBase.DBFactory   clsDbFac   =   new   DataBase.DBFactory();
                    string   sql2   =   "select   *   from   [USER]   where   USERNAME='"   +   this.txtUserName.Text   +   "'";   ;
                    DataTable   dt   =   clsDbFac.ExecuteSqlDataTable(sql2);
                    this.gdvUser.DataSource   =   dt;
                    this.gdvUser.DataKeyNames   =   new   string[]   {   "USERID"   };
                    this.gdvUser.DataBind();
            } 2. SQL查詢條件是否符合!先去掉查詢條件試試!