private void BindData()
{
DataTable dt = DAO.RunSQLReturnDt(this.getsql());
int dtcount = dt.Rows.Count;
if (dtcount == )
{
dt.Rows.Add(dt.NewRow());
}
DataView dv = dt.DefaultView;
//对用于分页的类的引用
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;//设置数据源(DataTable类型)
pds.AllowPaging = true;
//每页显示的行数
pds.PageSize = ;
AspNetPager1.RecordCount = dv.Count;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - ;
pds.PageSize = AspNetPager1.PageSize;
GridView1.DataSource = pds;
GridView1.DataBind();
if (dtcount <= )
{
int colnumcount = dt.Columns.Count;
GridView1.Rows[].Cells.Clear();
GridView1.Rows[].Cells.Add(new TableCell());
GridView1.Rows[].Cells[].ColumnSpan = colnumcount;
GridView1.Rows[].Cells[].Text = "没有相关记录";
GridView1.Rows[].Cells[].Style.Add("color", "red");
} }

页面正常显示

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="tablelist" GridLines="None" DataKeyNames="C_ID" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="C_AppNum" HeaderText="入库编号" SortExpression="C_AppNum">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField> <asp:BoundField DataField="C_AppDate" HeaderText="申请时间" SortExpression="C_AppDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="申请部门">
<ItemTemplate>
<%# XC.Depart.GetDepartName(Eval("C_AppDepartID").ToString()) %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="申请人">
<ItemTemplate>
<%# XC.User.GetUserName(Eval("C_AppUserID").ToString())%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="C_Status" HeaderText="状态" SortExpression="C_Status">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="C_AuditState" HeaderText="审核状态" SortExpression="C_AuditState">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField> </Columns>
<HeaderStyle HorizontalAlign="center" />
</asp:GridView>

效果

GridView 无数据时,绑定提示的更多相关文章

  1. ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)

    介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...

  2. 扩展:gridview 空数据时显示表头

    2015年7月14日16:50:06  Gridview 默认展示数据时,若数据为空,则表格不显示,显示不美观. 针对此问题进行扩展: using System.Web.UI.WebControls; ...

  3. UWP GridView切换数据时界面闪动

    在选择数据时,比如1-10集,和11-20集切换时,GridView需要切换对应的数据,但是会发生界面闪动. 这是默认的Item Transition导致的. 可以去掉默认的转换效果. <Gri ...

  4. 从Excel中导入数据时,提示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决办法

    注意,64位系统,用64位的补丁文件; https://www.cnblogs.com/A2008A/articles/2438962.html 操作系统:使用的是64位的Windows Server ...

  5. easyui 中Datagrid 控件在列较多且无数据时,列显示不全的解决方案

    在onLoadSuccess 中加入如下代码就OK啦 $('#dg3').datagrid({ onLoadSuccess:function(data){ if(data.total==0){ var ...

  6. 扩展当easyui datagrid无数据时,显示特定值。如:没有数据

    var myview = $.extend({},$.fn.datagrid.defaults.view,{ onAfterRender:function(target){ $.fn.datagrid ...

  7. vue-scroll 底部无数据时,底部出现大片的空白

    vue-scroll放在vue的项目中,实现下拉刷新的效果,但是发现,不能上拉的bug,上拉了之后,底部出现了一大段的空白,参照GitHub的问题,算是暂时解决了. 不能上拉的原因是:滑动标签里边的内 ...

  8. 使用Entity Framwork 保存数据时,提示不能在对象中插入重复键,违反了PRIMARY_KEY约束

    这种情况,大多发生在有外键存在的情况下,解决方法是: 把dataContext.Set<T>().Add(model)修改成dataContext.Models.Add(model);

  9. Repeater为空时显示“暂无数据”,很方便实用方法

    Repeater为空时显示“暂无数据”,很方便实用方法 <FooterTemplate>   <asp:Label ID="lblEmptyZP" Text=&q ...

随机推荐

  1. EditText的 焦点事件 setOnFocusChangeListener

    实现代码: //光标处在EditText时其内容消失 mInfo = (EditText)findViewById(R.id.old_password); //setOnFocusChangeList ...

  2. c++ 名字粉碎(name mangling)

    转自Ibm: Name mangling is the encoding of function and variable names into unique names so that linker ...

  3. 译文:TransactionScope 与 Async/Await

    你可能不知道这一点,在 .NET Framework 4.5.0  版本中包含有一个关于 System.Transactions.TransactionScope 在与 async/await 一起工 ...

  4. poj3373

    其实这道题只告诉了一个事当出现多个满足答案约束条件是,我们可以求一个再求一个,不要一下子全求完前两个条件怎么弄之前已经做过类似的了于是我们可以用记忆化搜索找出最小差异然后配合最小差异来剪枝,搜索出最小 ...

  5. Linux Shell编程(22)——时间/日期 命令

    date直接调用, date 就会打印日期和时间到 stdout 上. 这个命令有趣的地方在于它的格式化和分析选项上.time输出统计出来的命令执行的时间.touch这是一个用来更新文件被存取或修改的 ...

  6. 【狼】unity3d point light 个数限制更改

      unity默认的pointlight个数为2个,多加的话先加的就没有效果, 具体更改方式如下: Edit -> Project Settings -> Quality-> Ren ...

  7. 【转】unity3d input输入

    Input 输入 按键 Input.GetKey(“up”) = Input.GetKey(KeyCode.UpArrow) 按住键盘上键 Input.GetKeyDown (“up”) 按下键盘上键 ...

  8. PHP的哲学:Simple Is Hard

    原帖地址 PHP框架的繁荣是正确的发展方向吗?   作者 正文 poshboytl    发表时间:2009-01-19   最后修改:2009-04-06   做ROR有一年了, 感觉非常好.配合敏 ...

  9. Linq中小心使用IndexOf

      我们平常在做字符串的模糊查询时,有可能会用到下面的类似LINQ写法: string.IsNullOrEmpty(_SN) ? true : a.SN.IndexOf(_SN) != -1   这条 ...

  10. java---Unicode-字符转换器

    实现一个字符(包括汉字)的简单互相转换: package cn.hncu.gui2; import java.awt.Button; import java.awt.Color; import jav ...