【问题标题】:Insert error in Grid view在网格视图中插入错误
【发布时间】:2013-07-22 10:47:07
【问题描述】:

我是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(); 

附上错误图片。

【问题讨论】:

  • 什么是“客户”实例?显示您正在初始化事物的代码部分
  • 而您的PASSWORD TextBox object 没有.Text 属性,因为...??

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


【解决方案1】:
  1. 检查插入方法。
  2. 检查该页面的类名,无论是默认还是_Default。
  3. 交叉检查使用 CodeBehind 和 Inherits 属性的 aspx 文件(页面指令)的第一行。
  4. 最后检查 Default.aspx.designer.cs,

现在匹配所有默认值及其层次结构。将其更正为默认值。您的代码将运行良好。

更新

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,...);

}

【讨论】:

  • 你能简单解释一下吗?
  • 我的班级名称是_Default
  • 您的问题出在页面名称上。 _Default 和 Default 是根本原因。你能上传到某个地方并将文件 ASPX 和 Codebehind 的链接发送给我,以便我在线查看它们
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-30
相关资源
最近更新 更多