Syncfusion Datatabe网格绑定:在后面的代码中网格为空

时间:2018-07-20 20:30:41

标签: webforms grid syncfusion

我目前正在尝试对对象列表进行基本绑定。在后面的代码中,对Grid对象的引用为null。 以此为参考: AutoLab

.Net版本:4.6 网格的Syncfusion参考: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为空。这怎么可能?

1 个答案:

答案 0 :(得分:1)

According to your query you are facing an issue while binding dataSource to Grid. The reported issue occur because the Grid instance is initialized wrongly in the designer page and also dataSource is wrongly bounded to Grid. Kindly modify your sample as below code example

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

        }