loading data to datagrid in page_load event

I have to SfDataGrids on a tabcontrol.  I am trying to load data from a sql database into the datagrids in the page_load event.  I am using visual basic and the data will not load unless I put the query's in a button click event.  How can I get the sql data to load the grids in the page_load event?

1 Reply

JG Jai Ganesh S Syncfusion Team March 20, 2018 03:47 AM UTC

Hi David, 
 
We have prepared a sample for binding the data from  window loaded event and its working fine in our end. 
 
private void MainWindow_Loaded(object sender, RoutedEventArgs e) 
{ 
    this.PopulateData(); 
} 
 
private void PopulateData() 
{ 
    if (!LayoutControl.IsInDesignMode) 
    { 
        Random r = new Random(); 
        Northwind north = new Northwind(string.Format(@"Data Source= {0}", LayoutControl.FindFile("Northwind.sdf"))); 
 
        foreach (OrderDetails orderDet in north.OrderDetails.Take(50)) 
        { 
            OrderInfo orderInfo = new OrderInfo(); 
 
            orderInfo.OrderID = orderDet.OrderID; 
            orderInfo.CustomerID = orderDet.Orders.CustomerID; 
            orderInfo.ProductName = orderDet.Products.ProductName; 
            orderInfo.UnitPrice = (double)orderDet.UnitPrice; 
            orderInfo.Quantity = orderDet.Quantity; 
            orderInfo.Discount = Math.Round(orderDet.Discount, 2); 
            orderInfo.Freight = (double)orderDet.Orders.Freight; 
            orderInfo.OrderDate = (DateTime)orderDet.Orders.OrderDate; 
            orderInfo.ShippedDate = (DateTime)orderDet.Orders.ShippedDate; 
            orderInfo.ShipPostalCode = orderDet.Orders.ShipPostalCode; 
            orderInfo.ShipAddress = orderDet.Orders.ShipAddress; 
            orderInfo.IsClosed = r.Next() % 2 == 0 ? true : false; 
            orderInfo.ContactNumber = r.Next(999111, 999119).ToString(); 
            orderInfo.DeliveryDelay = orderInfo.ShippedDate - orderInfo.OrderDate; 
                   
            (this.DataContext as ViewModel).OrderList.Add(orderInfo); 
        } 
    } 
} 
 
 
Could you please check the above sample and if you still facing the issue then please share the more details or please replicate the issue in simple sample. This would be more helpful for us to proceed further. 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon