Grid Object Null in Code Behind, cannot bind datatable

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.

.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? 

5 Replies

VN Vignesh Natarajan Syncfusion Team July 23, 2018 12:39 PM UTC

Hi Matthew, 
Thanks for using Syncfusion products. 
According to your query you are facing an issue while binding dataSource to Grid. We have prepared a sample using your code snippet and we are able to reproduce the reported issue (gv is returned as null object).  
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();           
           
        } 
 
   
For your convenience we have prepared a sample which can be downloaded from below link 
 
 
 
Please get back to us if you have any queries. 
Regards, 
Vignesh Natarajan   




MA Matt July 25, 2018 03:26 PM UTC

Thank you, this has fixed my issue...though i am having issues displaying it (I believe its my javascript packages and their order)...do you have any insight to the packages I need for the grid and the order in which to load them in?


VN Vignesh Natarajan Syncfusion Team July 26, 2018 12:39 PM UTC

Hi Matthew, 


Thanks for the update. 


From your query, we understand that you are facing issue while displaying ejGrid. Reported issue may occur when theme (CSS) files are not properly referred. 

So kindly refer the below help documentation for order in which the scripts are to be referred in Site.Master or Master page. 



Also please ensure that you have refer the Grid dependency file in the following order. 


ej.web.all.min.css 
jquery.min.js 
jsrender.min.js 
ej.web.all.min.js 
ej.webform.min.js 




if you still face the issue kindly get back to us with following details. 
 
  1. Share the screenshot of issue you are facing (issue in displaying)
  2. Share the screenshot of script error in console window.
 
Regards, 
Vignesh Natarajan 






MA Matt July 26, 2018 10:52 PM UTC

Thank you, it ended up being actually on my site master page i was loading in jquery first, then the script block to load in the other stuff on the page. This fixes it. Thank you for the help


VN Vignesh Natarajan Syncfusion Team July 27, 2018 04:03 AM UTC

Hi Matthew, 

Thanks for the update.  

We are glad to hear that your query has been resolved by our solution.  

Please get back to us if you have further queries. 

Regards, 
Vignesh Natarajan  



Loader.
Up arrow icon