Example #1
0
        private void GridViewEmptyData()
        {
            DataTable tbl = new DataTable(); //创建一个DataTable对象

            //新增自定义的4列(即创建DataTable对象的骨架)
            tbl.Columns.Add("id");
            tbl.Columns.Add("name");
            tbl.Columns.Add("location");
            tbl.Columns.Add("date");

            if (tbl.Rows.Count == 0)
            {
                tbl.Rows.Add(tbl.NewRow());
            } // end if

            GridViewEmptyDataShow.DataSource = tbl;
            GridViewEmptyDataShow.DataBind();

            //如果绑定的数据为空,则创建GridView表头并显示提示信息
            int columnCount = tbl.Columns.Count;

            GridViewEmptyDataShow.Rows[0].Cells.Clear();
            GridViewEmptyDataShow.Rows[0].Cells.Add(new TableCell());
            GridViewEmptyDataShow.Rows[0].Cells[0].ColumnSpan = columnCount;
            GridViewEmptyDataShow.Rows[0].Cells[0].Text       = "无相关记录信息!";
            GridViewEmptyDataShow.Rows[0].Cells[0].Style.Add("text-align", "center");
        }
Example #2
0
        /// <summary>
        /// 普通空数据绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonNormalBind_Click(object sender, EventArgs e)
        {
            DataTable tbl = new DataTable();

            tbl.Columns.Add("id");
            tbl.Columns.Add("name");
            tbl.Columns.Add("location");
            tbl.Columns.Add("date");
            GridViewEmptyDataShow.DataSource = tbl;
            GridViewEmptyDataShow.DataBind();
        }
Example #3
0
        /// <summary>
        /// 构造空的DataTable绑定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ButtonConstructTableBind_Click(object sender, EventArgs e)
        {
            DataTable tbl = new DataTable();

            tbl.Columns.Add("id");
            tbl.Columns.Add("name");
            tbl.Columns.Add("location");
            tbl.Columns.Add("date");
            if (tbl.Rows.Count == 0)
            {
                tbl.Rows.Add(tbl.NewRow());
            }
            GridViewEmptyDataShow.DataSource = tbl;
            GridViewEmptyDataShow.DataBind();
        }