Request for code for Grid

I am  binding data coming as list not showing in grid ?
How can I bind the data in form of list coming from controller in grid ?

I need code for this in view and controller.

1 Reply

RU Ramdhas  Ueikattan Syncfusion Team January 5, 2017 12:51 PM UTC

Hi Ashwan, 

Thanks for contacting Syncfusion Supports. 


We have created a sample based on your requirement . please find the code example. 

@(Html.EJ().Grid<object>("Grid") 
                .Datasource((IEnumerable<object>)ViewBag.datasource) 
                .AllowPaging() 
                .Columns(col => 
                { 
                    col.Field("OrderID").HeaderText("OrderID").TextAlign(TextAlign.Right).Width(90).Add(); 
                    col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(90).Add(); 
                    col.Field("CustomerID").HeaderText("Customer ID").Width(100).Add(); 
                    col.Field("Freight").HeaderText("Freight").Format("{0:c2}").TextAlign(TextAlign.Right).Width(80).Add(); 
                     
                    
                }) 
            ) 
 
[controller]    
 
  public ActionResult Index(){ 
            var Data = GetData(); 
            ViewBag.dataSource = Data; 
            return View(); 
        } 
        public static List<Details> GetData() 
        { 
 
             List<Details> jsons = new List<Details>(); 
              
             int code = 1000; 
             for (int i = 1; i <= code; i++ ){ 
              jsons.Add(new Details(){ OrderID = code +i, EmployeeID =i, CustomerID= "ALAKI", Freight = code * 0.23}); 
                 jsons.Add(new Details(){ OrderID = code +i+1, EmployeeID =i, CustomerID= "VINET", Freight = code * 0.56}); 
                 jsons.Add(new Details() { OrderID = code +i+2 , EmployeeID = i, CustomerID = "TOMSP", Freight = code * 0.11 }); 
                 jsons.Add(new Details() { OrderID = code + i+3, EmployeeID = i, CustomerID = "VICTE", Freight = code * 0.44 }); 
                 i = i+4 ; 
             } 
             return jsons; 
                  
 
        } 
 
    public class Details { 
        public int OrderID { get; set; } 
        public int EmployeeID { get; set; } 
        public string CustomerID { get; set; } 
        public double Freight { get; set; } 
     
    } 
} 
 
 

For your convenience please find the sample . 





Thanks & Regards, 
Ramdhas U 


Loader.
Up arrow icon