C# GridView不包含';列';没有扩展方法';列';接受类型为'的第一个参数;GridView';可以找到

C# GridView不包含';列';没有扩展方法';列';接受类型为'的第一个参数;GridView';可以找到,c#,asp.net,gridview,C#,Asp.net,Gridview,在将我的aspx&cs文件复制到.NET framework 4.0后,我出现了上述错误。因为表单最初是在.NET framework 2.0上开发的。我不得不将它复制到Framework4.0,因为我需要在项目中使用图表控件。我浏览了网页,得到了结果 ***编译器错误消息:CS1061:“GridView”不包含“Columns”的定义,并且找不到接受“GridView”类型的第一个参数的扩展方法“Columns”(是否缺少using指令或程序集引用?)*** 这是cs文件的全部源代码 usi

在将我的aspx&cs文件复制到.NET framework 4.0后,我出现了上述错误。因为表单最初是在.NET framework 2.0上开发的。我不得不将它复制到Framework4.0,因为我需要在项目中使用图表控件。我浏览了网页,得到了结果

***编译器错误消息:CS1061:“GridView”不包含“Columns”的定义,并且找不到接受“GridView”类型的第一个参数的扩展方法“Columns”(是否缺少using指令或程序集引用?)***

这是cs文件的全部源代码

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Principal;
using System.Data.SqlClient;
using System.Data;

public partial class Survey : System.Web.UI.Page
{
    string responder = WindowsIdentity.GetCurrent().Name.ToString();
    int catID;
    int qID;
    int canteenID;
    string response;
    string comments;
    string comment;
    string responseDate = DateTime.Now.ToShortDateString().ToString();

    SqlDataSource sds1 = new SqlDataSource();
    //SqlDataSource sds2 = new SqlDataSource();



    protected void Page_Init(object sender, EventArgs e)
    {
        // set dataSource properties
        sds1.ConnectionString = "Data Source=BNY-D-1245;Initial Catalog=canteenSurvey;Integrated Security=True";
        sds1.ProviderName = "System.Data.SqlClient";

        //sds2.ConnectionString = "Data Source=BNY-D-1245;Initial Catalog=canteenSurvey;Integrated Security=True";
        //sds2.ProviderName = "System.Data.SqlClient";



        // bind datasource to page
        sds1.DataBind();
        //sds2.DataBind();
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void gvCategory_PreRender(object sender, EventArgs e)
    {
        foreach (GridViewRow item in gvCategory.Rows)
        {
            catID = (int)gvCategory.DataKeys[item.RowIndex].Value;

            GridView gvQuestion = (GridView)item.FindControl("gvQuestion");

            sds1.SelectCommand = "SELECT * FROM tblQuestion WHERE [CatID] = " + catID;

            gvQuestion.Columns[0].Visible = true;            
            gvQuestion.DataSource = sds1;
            gvQuestion.DataBind();
            gvQuestion.Columns[0].Visible = false;

            foreach (GridViewRow row in gvQuestion.Rows)
            {
                qID = (int)gvQuestion.DataKeys[row.RowIndex].Value;
            }

        }

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow masterItem in gvCategory.Rows)
        {
            catID = (int)gvCategory.DataKeys[masterItem.RowIndex].Value;

            GridView gvQuestion = (GridView)masterItem.FindControl("gvQuestion");

            foreach (GridViewRow masterRow in gvQuestion.Rows)
            {
                qID = (int)gvQuestion.DataKeys[masterRow.RowIndex].Value;

                GridView gvCanteen = (GridView)masterRow.FindControl("gvCanteen");

                foreach (GridViewRow masterData in gvCanteen.Rows)
                {
                    canteenID = (int)gvCanteen.DataKeys[masterData.RowIndex].Value;
                    response = ((DropDownList)masterData.FindControl("ddlResponse")).SelectedValue;

                    comments = txtComments.Text;
                    // Insert into the database

                    string constr = "Data Source=BNY-D-1245;Initial Catalog=canteenSurvey;Integrated Security=True";

                    // SQL Query to insert values into the database

                    string sqlQuery = "INSERT INTO tblFeedBack (catID, qID, canteenID, responseID, responder, responseDate)";
                    sqlQuery += "VALUES (@catID, @qID, @canteenID, @responseID, @responder, @responseDate )";

                    //string sqlQuery2 = "INSERT INTO tblComments (responder, comments) VALUES (@responder, @comments)";

                    //SqlCommand query = new SqlCommand();
                    using (SqlConnection dataConnection = new SqlConnection(constr))
                    {
                        using (SqlCommand dataCommand = dataConnection.CreateCommand())
                        {
                            dataConnection.Open();
                            dataCommand.CommandType = CommandType.Text;
                            dataCommand.CommandText = sqlQuery;
                            dataCommand.Parameters.AddWithValue("@catID", catID);
                            dataCommand.Parameters.AddWithValue("@qID", qID);
                            dataCommand.Parameters.AddWithValue("@canteenID", canteenID);
                            dataCommand.Parameters.AddWithValue("@responseID", response);
                            dataCommand.Parameters.AddWithValue("@responder", responder);
                            dataCommand.Parameters.AddWithValue("@responseDate", responseDate);

                            dataCommand.ExecuteNonQuery();
                            dataConnection.Close();
                        }

                    }



                }
            }
        }        
    }
}

我是asp.net新手,因此我能得到的每一个帮助都会得到通知。

尝试将页面上的
CodeFile
属性替换为
codebeard
属性:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Survey.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="Survey" %>

尝试用页面上的
codebeard
属性替换
CodeFile
属性:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Survey.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="Survey" %>

尝试用页面上的
codebeard
属性替换
CodeFile
属性:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Survey.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="Survey" %>

尝试用页面上的
codebeard
属性替换
CodeFile
属性:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Survey.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="Survey" %>

您收到错误:CS1061

尝试调用方法或访问类时会发生此错误 不存在的成员

参考:

所以我可以说你在复制和粘贴方面犯了一些错误。您不应该复制整个页面,而应该复制aspx页面的唯一网格内容以及aspx.cs的相同内容。只复制那些需要复制的代码


例如:在页面属性中,您对代码文件继承有一些错误的值,您得到了错误:CS1061

尝试调用方法或访问类时会发生此错误 不存在的成员

参考:

所以我可以说你在复制和粘贴方面犯了一些错误。您不应该复制整个页面,而应该复制aspx页面的唯一网格内容以及aspx.cs的相同内容。只复制那些需要复制的代码


例如:在页面属性中,您对代码文件继承有一些错误的值,您得到了错误:CS1061

尝试调用方法或访问类时会发生此错误 不存在的成员

参考:

所以我可以说你在复制和粘贴方面犯了一些错误。您不应该复制整个页面,而应该复制aspx页面的唯一网格内容以及aspx.cs的相同内容。只复制那些需要复制的代码


例如:在页面属性中,您对代码文件继承有一些错误的值,您得到了错误:CS1061

尝试调用方法或访问类时会发生此错误 不存在的成员

参考:

所以我可以说你在复制和粘贴方面犯了一些错误。您不应该复制整个页面,而应该复制aspx页面的唯一网格内容以及aspx.cs的相同内容。只复制那些需要复制的代码



例如:在页面属性中,您对CodeFileInherits

有一些错误的值。请构建应用程序。我已经构建了应用程序,但仍然收到相同的错误。您可以发布您的aspx代码吗?好的,请详细编写gridview的aspx代码。aspx和cs代码都在这个页面上发布请构建应用程序我已经构建了应用程序,我仍然收到相同的错误。你可以发布你的aspx代码吗?好的,你可以详细地为gridview编写aspx代码吗。aspx和cs代码都在这篇文章中。请构建应用程序我已经构建了应用程序,我仍然收到相同的错误。你可以发布你的aspx吗代码?好的,请你详细写下gridview的aspx代码。aspx和cs代码都在这篇文章中。请构建应用程序。我已经构建了应用程序,但我仍然收到相同的错误。你可以发布你的aspx代码吗?好的,请你详细写下gridview的aspx代码。aspx和cs代码都在这篇文章中试过你的方法,我还是有同样的错误。我将检查我的方法调用。我尝试了你的方法,但仍然有相同的错误。我将检查我的方法调用。我尝试了你的方法,但仍然有相同的错误。我将检查我的方法调用。我尝试了你的方法,但仍然有相同的错误。我将检查我的方法调用。