zoukankan      html  css  js  c++  java
  • 今天想 做了一下 gridview 在没有数据的情况下 也能显示表头呢 虽然 没有封装 还是面向过程的 不过 还是做出来了

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
          
               
    
                Bind();
               
    
            }
        }
        public void Bind()
        {
    
    
            string sqlstr = "select [Thesis].Lwid,[Issue].Kttm,[Thesis].LNd,[Thesis].Sci,[Thesis].lwtitle,[Periodical_Type].qklx,[Periodical].Qkmc,[Thesis_Author].Zzxm,[Issue_Groups].Zbmc from [Issue_Thesis_Relation],[Issue],[Thesis],[Thesis_Author],[Thesis_Author_Relation],[Issue_Groups],[Periodical],[Periodical_Type]  where [Issue_Groups].Zid = [Issue].Zid and [Issue_Thesis_Relation].Ktid =[Issue].Ktid and [Issue_Thesis_Relation].Lwid = [Thesis].Lwid and [Periodical].lid = [Periodical_Type].lid and [Thesis].qkid = [Periodical].qkid and [Thesis_Author_Relation].Lwid = [Thesis].Lwid and [Thesis_Author_Relation].Zzid = [Thesis_Author].Zzid";
            DataSet myds = new DataSet();
            myds = SQLHelper.GetDataSet(sqlstr);
    
            int Sqlcount = myds.Tables[0].Rows.Count;//总记录数
            this.AspNetPager1.RecordCount = Sqlcount;
            AspNetPager1.AlwaysShow = true;
            int pageSize = this.AspNetPager1.PageSize = 10;//每页记录数
            int startIndex = (this.AspNetPager1.CurrentPageIndex - 1) * pageSize + 1;//每页最开始索引
            int startindex1 = startIndex + 10;
            string sqlstr1 = "select * from(select ROW_NUMBER() over(order by [Thesis].CreateTime desc) row,[Thesis].Lwid,[Issue].Kttm,[Thesis].LNd,[Thesis].Sci,[Thesis].lwtitle,[Periodical_Type].qklx,[Periodical].Qkmc,[Thesis_Author].Zzxm,[Issue_Groups].Zbmc from [Issue_Thesis_Relation],[Issue],[Thesis],[Thesis_Author],[Thesis_Author_Relation],[Issue_Groups],[Periodical],[Periodical_Type]  where [Issue_Groups].Zid = [Issue].Zid and [Issue_Thesis_Relation].Ktid =[Issue].Ktid and [Issue_Thesis_Relation].Lwid = [Thesis].Lwid and [Periodical].lid = [Periodical_Type].lid and [Thesis].qkid = [Periodical].qkid and [Thesis_Author_Relation].Lwid = [Thesis].Lwid and [Thesis_Author_Relation].Zzid = [Thesis_Author].Zzid)a where a.row>='" + startIndex + "'and a.row<'" + startindex1 + "'";
            DataSet myds1 = new DataSet();
            myds1 = SQLHelper.GetDataSet(sqlstr1);
            if (myds1.Tables[0].Rows.Count != 0)
            {
                GridView1.DataSource = myds1;
                GridView1.DataBind();
            }
            else
            {  
                DataTable mytable = new DataTable();
                mytable.Columns.Add("CssClass", System.Type.GetType("System.String"));
                mytable.Columns.Add("lwid");
                mytable.Columns.Add("lwtitle");
                mytable.Columns.Add("qklx");
                mytable.Columns.Add("Qkmc");
                mytable.Columns.Add("Zzxm");
                mytable.Columns.Add("Sci");
                mytable.Columns.Add("Zbmc");
                mytable.Columns.Add("LNd");
                mytable.Columns.Add("kttm");
                DataRow myrow = mytable.NewRow();
                mytable.Rows.Add(myrow);
                DataSet myset = new DataSet();
                myset.Tables.Add(mytable);
                GridView1.DataSource = myset;
                GridView1.DataBind();
                GridView1.Rows[0].Visible = false;
    
            
            }
    
    
    
        }
    

      

  • 相关阅读:
    CodeForces Round #516 Div2 题解
    BZOJ3300: [USACO2011 Feb]Best Parenthesis 模拟
    BZOJ4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III 树状数组
    BZOJ3297: [USACO2011 Open]forgot DP+字符串
    BZOJ3296: [USACO2011 Open] Learning Languages 并查集
    BZOJ2442: [Usaco2011 Open]修剪草坪 单调队列优化dp
    BZOJ3298: [USACO 2011Open]cow checkers 威佐夫博弈
    什么是 DDoS 攻击?
    快速了解“云原生”(Cloud Native)和前端开发的技术结合点
    一文读懂spring boot 和微服务的关系
  • 原文地址:https://www.cnblogs.com/haihang/p/2778912.html
Copyright © 2011-2022 走看看