在网格视图中插入错误

时间:2013-07-22 10:47:07

标签: c# asp.net gridview master-pages

我是asp的新手,我的代码中有错误,有人可以帮我吗?

     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
  if (e.CommandName.Equals("AddNew")) 
  { 
   TextBox txtUsername=(TextBox)GridView1.FooterRow.FindControl("txtUsername"); 
   TextBox PASSWORD=(TextBox)GridView1.FooterRow.FindControl("PASSWORD"); 
   TextBox txtStatus = (TextBox)GridView1.FooterRow.FindControl("txtStatus"); 
   TextBox txtE_MAIL = (TextBox)GridView1.FooterRow.FindControl("txtE_MAIL");

   customer.Insert(txtUsername.Text, PASSWORD, txtStatus.Text, txtE_MAIL.Text) ; 
     BindEmployeeDetails(); 

附上错误图片。enter image description here

1 个答案:

答案 0 :(得分:0)

  1. Checkout for Insert方法。
  2. 检查该页面的类名称,无论是Default还是_Default。
  3. 交叉检查aspx文件的第一行(Page Directive),其中使用了CodeBehind和Inherits属性。
  4. 最后检查Default.aspx.designer.cs,
  5. 现在匹配所有默认值及其heirarchy。将其更正为默认值。你的代码运行正常。

    更新

    public partial class _Default : System.Web.UI.Page
    {
        _Default customer=new _Default();
        customer.Insert()//
    }
    

    你的问题在于这些问题。您正在_Default类中创建_Default类的新对象。这是假设它正在访问自己的成员。表示在区域内写的代码

    public partial class _Default : System.Web.UI.Page
    {
    
    
    }
    

    这里它的对象客户无法找到Insert()。我想你还有一些同名的班级。您可以将其标记为部分类而不使用customer.Insert();而不是创建新对象,而是访问Insert();

    您的新代码将是

    public partial class _Default : System.Web.UI.Page
    {
     //_Default customer=new _Default();// no need to write this
       // customer.Insert()// no need to write this too
    
    // simply mark the class contaning Insert with "partial class _Default" and
    //acess the Insert directly
    
    Insert(txt1.text, txt2.text,...);
    
    }