简体   繁体   中英

Unable to show data on data grid view

I have problems showing my data inside the data into the data grid view. Can anyone help to solve because they never prompt me any errors while compiling and there are also data inside the database. What comes out inside the data grid view is only the columns and no data inside.

private void LoadAllEmpShift()
    {
        using (testEntities Setupctx = new testEntities())
        {
            var Viewemp = from ES in Setupctx.employeeshifts
                          join shifthour sh in Setupctx.shifthours on ES.ShiftHourID equals sh.idShiftHours
                         select new
                         {
                             ES.idEmployeeShift,
                             ShiftHour_Start = sh.shiftTiming_start,
                             ShiftHour_Stop = sh.shiftTiming_stop,
                             ES.EmployeeName,
                             ES.StartTime,
                             ES.EndTime,
                             ES.Date
                         };
            dgvShift.DataSource = Viewemp;
        }
    }

Any help will be greatly appreciated.

After setting the DataSource property, you need to call

dgvShift.DataBind();

Edit:

I believe the above is for a DataGrid / GridView (in case anyone is using those controls).

For DataGridView, you need to have a BindingSource.

Add the BindingSource control to your form, then set the DataSource property of the BindingSource to Viewemp

dgvBindingSource.DataSource = Viewemp;
dgvShift.DataSource = dgvBindingSource; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM