首页 > 代码库 > GridView中如何在无数据时显示空行和表头
GridView中如何在无数据时显示空行和表头
#region ---- 数据绑定 ----- private void bd(int pageindex) { int rowcount = 0; int pagesize = 0; int pagecount = 0; decimal cyfzhj = 0; string Slqstring = Base_Query_Sql; mta.DT(Slqstring); DataTable rs = mta.DT(Slqstring); this.GridView1.DataSource = rs; rowcount = rs.Rows.Count; if (rowcount == 0) { rs.Columns.Clear(); rs.Columns.Add("nid"); rs.Columns.Add("title"); rs.Columns.Add("nTime"); rs.Columns.Add("una"); rs.Columns.Add("author"); rs.Columns.Add("yhm"); rs.Columns.Add("shbz"); rs.Columns.Add("shTime"); rs.Columns.Add("ssbm"); rs.Columns.Add("csTime"); rs.Columns.Add("cyTime"); rs.Columns.Add("shbzmc"); rs.Columns.Add("cyfz"); DataRow dr = rs.NewRow(); dr["nid"] = " "; dr["title"] = " "; dr["nTime"] = " "; dr["una"] = " "; dr["author"] = " "; dr["yhm"] = " "; dr["shbz"] = " "; dr["shTime"] = " "; dr["ssbm"] = " "; dr["csTime"] = " "; dr["cyTime"] = " "; dr["shbzmc"] = " "; dr["cyfz"] = " "; rs.Rows.Add(dr); this.GridView1.DataBind(); return; } pagesize = this.GridView1.PageSize; pagecount = rowcount / pagesize; if (pagecount * pagesize < rowcount) { pagecount = pagecount + 1; } if (((pageindex > pagecount - 1) && (pagecount != 0)) || (pageindex < 0))//如果给定的pageindex超出范围 { pageindex = pagecount - 1; } GridView1.PageIndex = pageindex; GridView1.EditIndex = -1; GridView1.DataKeyNames = new string[] { "nid" }; this.GridView1.DataBind(); } #endregion绑定之前判断datatable是否为空
如果为空 手工加入一行数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。