• GridView無數據時,顯示表頭


       DataTable dtTmp
        {
            get
            {
                if (ViewState["dtTmp"] == null)
                {
                    return null;
                }
                return ViewState["dtTmp"] as DataTable;
            }
            set
            {
                ViewState["dtTmp"] = value;
            }
        }
    
      private void GridBind()
        {
    
       //BLL層調用DAL層 function()
            dtTmp = NoPayManager.AccessObject.SlctDate();
            GridNoPay.DataSource = dtTmp;
            GridNoPay.DataBind();
        }
    
     #region 產生GirdView空白表頭
    
        protected void GridNoPay_PreRender(object sender, EventArgs e)
        {
            if (dtTmp != null)
            {
                if (dtTmp.Rows.Count == 0 || this.GridNoPay.Rows.Count == 0)
                {
                    renderEmptyGridView(this.GridNoPay, DAL.NoPayDao.GetRenderEmptyGridViewColumnNames(this.dtTmp));
                }
            }
        }
        /// <summary>
        /// 產生空白表頭
        /// </summary>
        /// <param name="GridView"></param>
        /// <param name="ColumnNames"></param>1
        public static void renderEmptyGridView(GridView GridView, string ColumnNames)
        {
            try
            {
                DataTable dt = new DataTable();
    
                char[] separator = { ',' };
    
                string[] columnNames = ColumnNames.Split(separator);
    
                #region "   空白表頭"
    
                //GridView無資料時,新增DataColumn
                foreach (string columnName in columnNames)
                {
                    DataColumn dataColumn = new DataColumn(columnName.Trim());
                    dt.Columns.Add(dataColumn);
                }
    
                //GridView無資料時,新增DataRow
                DataRow DataRow = dt.NewRow();
                foreach (string columnName in columnNames)
                {
                    DataRow[columnName.Trim()] = System.DBNull.Value;
                }
                dt.Rows.Add(DataRow);
    
                #endregion
    
                GridView.DataSourceID = null;
    
                GridView.DataSource = dt;
    
                GridView.DataBind();
    
                GridView.Rows[0].Visible = false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
    
    //DAL:
    
      public static readonly NoPayDao AccessObject = new NoPayDao();
            //  string SqlCon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            public static string GetRenderEmptyGridViewColumnNames(DataTable DT)
            {
                try
                {
                    string data = string.Empty;
                    for (int i = 0; i < DT.Columns.Count; i++)
                    {
                        data += (i == 0 ? string.Empty : ",");
                        data += DT.Columns[i].ColumnName;
                    }
                    return data;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            public DataTable SlctDate()
            {
                string sql = @"select  t.leaveid, t.leavename, t.status, to_char(t.starttime,'yyyy/mm/dd') starttime, to_char(t.endtime,'yyyy/mm/dd') endtime, t.updateby,t.updatetime
                                 from  lookup t ORDER BY  t.leaveid";
                try
                {
                    // DataSet ds = new DataSet();
                    DataSet ds = OracleHelper.Query(sql, "Pay");
                    //if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    //{
                          return ds.Tables[0];
                    //}
                    //else
                    //{
                    //    return null;
                    //}
                }
                catch
                {
                    throw new Exception();
                }
            }
     
    
  • 相关阅读:
    逆向笔记——PE文件相对虚拟地址(RVA)转文件偏移地址(FOA)
    逆向笔记——在PE任意一个节中添加代码
    FFT的物理意义
    Hilbert-Huang Transform: matlab 希尔伯特-黄变换: matlab实现
    交叉验证 Cross validation
    AAL template: ROI to brain lobe
    Types of intraclass correlation coefficience (ICC)
    统计:P值 & α值
    Notes: sensitivity & specificity
    Meet Github
  • 原文地址:https://www.cnblogs.com/Shirly-Zhang/p/5230164.html
Copyright © 2020-2023  润新知