名称“dgDataGrid”在当前上下文 C# ASP 中不存在

本文关键字:上下文 ASP 不存在 dgDataGrid 名称 | 更新日期: 2023-09-27 18:31:37

我在 C# 代码中收到以下错误:

The name 'dgDataGrid' does not exist in the current context

底部两行是引用它的行:

    drDataRow[mbNumCount + 1] = rvRowValue;
        }
        raDataTable.Rows.Add(drDataRow);
        tsseg++;
    }
    dgDataGrid.DataSource = raDataTable;
    dgDataGrid.DataBind();

"设计"http://i44.tinypic.com/jhez46.png 的屏幕截图

请告诉我,因为我相当困在这个..

设计器.cs代码:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace New_Solution
{

public partial class Default
{
    /// <summary>
    /// form1 control.
    /// </summary>
    /// <remarks>
    /// Auto-generated field.
    /// To modify move field declaration from designer file to code-behind file.
    /// </remarks>
    protected global::System.Web.UI.HtmlControls.HtmlForm form1;
    protected global::System.Web.UI.WebControls.GridView dgDataGrid;
}
}

名称“dgDataGrid”在当前上下文 C# ASP 中不存在

问题可能是 dgDataGrid 没有自动添加到设计器.cs文件中。如果是这种情况,请手动将其添加到设计器中。

将这些行添加到默认的.aspx.designer.cs文件中

        /// <summary>
        /// dgDataGrid control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.GridView dgDataGrid;