Syncfusion Datatabe 网格绑定:代码隐藏中的网格为空

Syncfusion Datatabe Grid Bind: Grid is Null in Code Behind

我目前正在尝试对对象列表进行基本绑定。在后面的代码中,对 Grid 对象的引用为空。 以此为参考: https://help.syncfusion.com/aspnet/grid/data-binding#datatable

.网络版本:4.6 网格同步融合参考:Syncfusion.Javascript.Web.Grid

在设计器中定义为:

Syncfusion.Javascript.Grid<myEntity> gv;

在aspx页面上:

<ej:Grid Id="gv" runat="server" />

在页面加载函数后面的代码中:

var myList = new List<myEntity>(){new myEntity()};
gv.GridModel.DataSource = myList;

但是在调试时显示 gv 为空。这怎么可能?

根据您的查询,您在将 dataSource 绑定到 Grid 时遇到了问题。报告的问题的发生是因为 Grid 实例在设计器页面中被错误地初始化,并且 dataSource 被错误地绑定到 Grid。请按照以下代码示例修改您的示例

GridFeatures.aspx.designer.cs

namespace SyncfusionASPNETApplication18  
{ 
   public partial class GridFeatures  
    { 
            protected global::Syncfusion.JavaScript.Web.Grid gv;     
    } 
} 

GridFeatures.aspx

<ej:Grid ID="gv" runat="server"/> 

GridFeatures.aspx.cs

protected void Page_Load(object sender, EventArgs e) 
        { 
            BindDataSource(); 
        } 
        private void BindDataSource() 
        { 
int code = 10000; 
            for (int i = 1; i < 10; i++) 
            { 
                order.Add(new Orders(code + 1, "TOMSP", i + 0, 2.3 * i, "Münster", "Toms Spezialitäten", new DateTime(1991, 05, 15), new DateTime(1991, 05, 15), "Germany", "44087", false)); 

            .             .               .                 .               .             
            this.gv.DataSource = order; 
            this.gv.DataBind();           

        }