Example #1
0
        void BindGridEmployeeAttendance()
        {
            try
            {
                string OCODE = ((SessionUser)Session["SessionUser"]).OCode;
                using (ERPSSLHBEntities context = new ERPSSLHBEntities())
                {
                    if (context.HRM_ATTENDANCE.Count() > 0)
                    {
                        var row = objAtt_BLL.GetAllOTByDate(OCODE, Convert.ToDateTime(txtDateFrom.Text), Convert.ToDateTime(txtDateTo.Text)).ToList();
                        if (row.Count > 0)
                        {
                            GridViewEMP_AT.DataSource = row.ToList();
                            GridViewEMP_AT.DataBind();
                        }
                    }
                    else
                    {
                        var obj = new List <HRM_ATTENDANCE>();
                        obj.Add(new HRM_ATTENDANCE());

                        // Bind the DataTable which contain a blank row to the GridView
                        GridViewEMP_AT.DataSource = obj;
                        GridViewEMP_AT.DataBind();

                        int columnsCount = GridViewEMP_AT.Columns.Count;
                        GridViewEMP_AT.Rows[0].Cells.Clear();                      // clear all the cells in the row
                        GridViewEMP_AT.Rows[0].Cells.Add(new TableCell());         //add a new blank cell
                        GridViewEMP_AT.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell

                        GridViewEMP_AT.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
                        GridViewEMP_AT.Rows[0].Cells[0].ForeColor       = System.Drawing.Color.Red;
                        GridViewEMP_AT.Rows[0].Cells[0].Font.Bold       = true;

                        //set No Results found to the new added cell
                        GridViewEMP_AT.Rows[0].Cells[0].Text = "NO RECORDS FOUND!";
                    }
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "func('" + ex.Message + "')", true);
            }
        }