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. Connect them

    zoj3204: 最小生成树,要求最小字典序的解. 用kruscal算法,先排序,输出的时候也要排序. /* zoj3204 解题思路: 赤裸裸的最小生成树.只是要求输出字典序最小的连接方案. 所以在 ...

  2. Android 隐式意图 让用户选择一个浏览器访问网址

    Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.setData(Uri.parse("h ...

  3. 更改linux系统时间

    date  //查看时间 date -s '21:04:20 2014-06-06' //将时间设为21:04:20 2014-06-06

  4. Qt4.8 移植(超详细Configure的参数)

    Qt4.8.6 configure 参数 不只是适用于Qt4.8.6,原则上适用于Qt4所有版本 Usage: configure [-h] [-prefix <dir>] [-prefi ...

  5. spin_count

    oracle的一个隐藏参数_spin_count当中记录了这个值,如果超过这个参数就那这个进程就释放cpu进入睡眠状态.(然后这里有了争议,传统的说法是在睡眠了一段时间以后会醒来,但是也有人说是进入了 ...

  6. [LeetCode#128]Word Ladder II

    Problem: Given two words (start and end), and a dictionary, find all shortest transformation sequenc ...

  7. Candies(差分约束)

    http://poj.org/problem?id=3159 题意: flymouse是幼稚园班上的班长,一天老师给小朋友们买了一堆的糖果,由flymouse来分发,在班上,flymouse和snoo ...

  8. bzoj2821

    其实和bzoj2724是一样的都是先处理多个块的答案,然后多余部分暴力空间要注意一下,还是O(nsqrt(n)); ..,..] of longint; g:..,..] of longint; a, ...

  9. Django中的CSRF

    CSRF(Cross Site Request Forgery, 跨站域请求伪造) CSRF 背景与介绍 CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的 ...

  10. 上海Uber优步司机奖励政策(1月25日~1月31日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...