zoukankan      html  css  js  c++  java
  • 当GridView没有数据时显示Header或Footer

    方法:只要在要绑定的DataTable中加入一个空行即可

    注意:如果模版行中有类似Button等控件,空行就会显示出来;可以将Button的Visiable设置为false,或将整行Visiable设置为false就可以了

    HTML代码
            <asp:gridview id="gv" autogeneratecolumns="false" runat="server">
                
    <columns>
                    
    <asp:templatefield headertext ="id">
                        
    <itemstyle width="120" />
                        
    <itemtemplate>
                            
    <%#Eval("id"%></itemtemplate>
                        
    <footertemplate>
                            
    <asp:textbox id="txtId" runat="server"></asp:textbox></footertemplate>
                    
    </asp:templatefield>
                    
    <asp:templatefield headertext ="name">
                    
    <itemstyle width="120" />
                        
    <itemtemplate>
                            
    <%#Eval("name"%></itemtemplate>
                        
    <footertemplate>
                            
    <asp:textbox id="txtName" runat="server"></asp:textbox></footertemplate>
                    
    </asp:templatefield>
                
    </columns>
            
    </asp:gridview>
    C#代码
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable tbl 
    = new DataTable();
            tbl.Columns.Add(
    new DataColumn("id"));
            tbl.Columns.Add(
    new DataColumn("name"));

            tbl.Rows.Add(tbl.NewRow());
    //添加空行
            
    //gv.ShowFooter = true; //需要显示Footer就加入这行代码
            gv.DataSource = tbl;
            gv.DataBind();
        }
    效果图如下:

    id name

    id name

  • 相关阅读:
    我的又一个web2.0作品
    AjaxPro使用注意事项与返回数据库中数据时2.0和3.5/4.0的区别(我的心得)
    AjaxPro入门使用方法
    SQLHelper的简单应用,高手绕道,写出最近用的一个类,仅供初学者参考
    Notepad++插件NPPExec编译运行C++、JAVA和Python代码
    在Ubuntu 18.04 LTS上搭建SS并启用BBR
    Linux 目录和文件管理
    chap06
    三层交换机的VLAN划分
    传输协议
  • 原文地址:https://www.cnblogs.com/andy65007/p/1632430.html
Copyright © 2011-2022 走看看