GridView 无数据时,绑定提示
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 无数据时,绑定提示的更多相关文章
- ASP.NET 使用AJAX让GridView的数据行显示提示框(ToolTip)
介绍ASP.NET AJAX可以使你的web应用程序具有更丰富的功能和更多的用户响应. 本文中,我将演示如何通过ASP.NET AJAX的帮助,给像GridView这样的数据绑定控件的数据行增加pop ...
- 扩展:gridview 空数据时显示表头
2015年7月14日16:50:06 Gridview 默认展示数据时,若数据为空,则表格不显示,显示不美观. 针对此问题进行扩展: using System.Web.UI.WebControls; ...
- UWP GridView切换数据时界面闪动
在选择数据时,比如1-10集,和11-20集切换时,GridView需要切换对应的数据,但是会发生界面闪动. 这是默认的Item Transition导致的. 可以去掉默认的转换效果. <Gri ...
- 从Excel中导入数据时,提示“未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序”的解决办法
注意,64位系统,用64位的补丁文件; https://www.cnblogs.com/A2008A/articles/2438962.html 操作系统:使用的是64位的Windows Server ...
- easyui 中Datagrid 控件在列较多且无数据时,列显示不全的解决方案
在onLoadSuccess 中加入如下代码就OK啦 $('#dg3').datagrid({ onLoadSuccess:function(data){ if(data.total==0){ var ...
- 扩展当easyui datagrid无数据时,显示特定值。如:没有数据
var myview = $.extend({},$.fn.datagrid.defaults.view,{ onAfterRender:function(target){ $.fn.datagrid ...
- vue-scroll 底部无数据时,底部出现大片的空白
vue-scroll放在vue的项目中,实现下拉刷新的效果,但是发现,不能上拉的bug,上拉了之后,底部出现了一大段的空白,参照GitHub的问题,算是暂时解决了. 不能上拉的原因是:滑动标签里边的内 ...
- 使用Entity Framwork 保存数据时,提示不能在对象中插入重复键,违反了PRIMARY_KEY约束
这种情况,大多发生在有外键存在的情况下,解决方法是: 把dataContext.Set<T>().Add(model)修改成dataContext.Models.Add(model);
- Repeater为空时显示“暂无数据”,很方便实用方法
Repeater为空时显示“暂无数据”,很方便实用方法 <FooterTemplate> <asp:Label ID="lblEmptyZP" Text=&q ...
随机推荐
- 使用Aspose.Word的基础知识整理
var doc = new Document(path); doc.AcceptAllRevisions();//接受所有修订
- CSS3 :nth-of-type() 选择器
可以设定第几个元素的样式 案例 css .qrcode img { margin-top: 30px; } .qrcode p:nth-of-type(1) { /*第一个p*/ font-size: ...
- 数学(概率)CodeForces 626D:Jerry's Protest
Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds ...
- 最大流算法---Edmond-Karp
这个算法是基于FF方法,就是通过不断求残余网络的增广路来增广流量,直到找不到增广路为止.注意:每次找到增广路以后都要更新原网络.EK算法通过BFS寻找源S到汇T的一条最短路径,因此时间复杂度是O(VE ...
- ACM1997_汉诺栽塔VII
#include <stdio.h> #include <iostream> #include <queue> #include <stdlib.h> ...
- [ReadingNotes] Search the links, static final in the java
[ReadingNotes] Search the links, static final in the java */--> pre { background-color: #2f4f4f;l ...
- Nginx + Tomcat 动静分离实现负载均衡
0.前期准备 使用Debian环境.安装Nginx(默认安装),一个web项目,安装tomcat(默认安装)等. 1.一份Nginx.conf配置文件 # 定义Nginx运行的用户 和 用户组 如果对 ...
- 【PNG格式中文详解】
技术文档(Document) PNG格式 PNG是20世纪90年代中期开始开发的图像文件存储格式,其目的是企图替代GIF和TIFF文件格式,同时增加一些GIF文件格式所不具备的特性.流式网 ...
- MongoDB基础知识 01
MongoDB基础知识 1. 文档 文档是MongoDB中的数据的基本单元,类似于关系型数据库管理系统的行. 文档是键值对的一个有序集.通常包含一个或者多个键值对. 例如: {”greeting& ...
- win8.1 无法安装 net framework3.5的解决办法
近期给重装系统时,发现Windows8.1无法安装.net framework 3.5,即使我离线下载了安装文件,还要求安装2.0和3.0....而且无法从Windows更新中获取,因此百度到以下方案 ...