Search code examples
webformsgridsyncfusion

Syncfusion Datatabe Grid Bind: Grid is Null in Code Behind


Im currently trying to do a basic bind on a list of objects. In the code behind, the reference to the Grid object is null. Using this as a reference: https://help.syncfusion.com/aspnet/grid/data-binding#datatable

.Net Version: 4.6 Syncfusion reference for grid: Syncfusion.Javascript.Web.Grid

In the designer it is defined as:

Syncfusion.Javascript.Grid<myEntity> gv;

On the aspx page:

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

And in the code behind on the page load function:

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

But while debugging it shows that gv is null. How is this possible?


Solution

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