当数据库返回null值时,如何在gridview中显示正确的消息? [英] How to display proper message in gridview when database returns null value ?

查看:63
本文介绍了当数据库返回null值时,如何在gridview中显示正确的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案:

在Gridview_Paint事件中



  private   void  gvwPrinterLocation_Paint( object  sender,PaintEventArgs e)
{
尝试
{
DataGridView sndr =(DataGridView)sender;
if (sndr.Rows.Count == 0 // < - 如果DataGridView中没有行绘制,那么它将创建您的消息
{
使用(Graphics grfx = e.Graphics)
{
grfx.DrawString( 找不到数据! new 字体( Arial 12 ),Brushes.Black, new PointF( 25 25 ));
}
}
}
catch (例外情况)
{}}

解决方案

请在gridview中添加以下代码。



 <   asp:GridView     ID   =  gdvId    runat   = 服务器 >  
< >
< /列 >
< EmptyDataTemplate >
找不到资源。
< / EmptyDataTemplate >
< / asp:GridView >


Solution:
In Gridview_Paint event

private void gvwPrinterLocation_Paint(object sender, PaintEventArgs e)
       {
           try
           {
               DataGridView sndr = (DataGridView)sender;
               if (sndr.Rows.Count == 0) // <-- if there are no rows in the DataGridView when it paints, then it will create your message
               {
                   using (Graphics grfx = e.Graphics)
                   {
                       grfx.DrawString("No data found!", new Font("Arial", 12), Brushes.Black, new PointF(25, 25));
                   }
               }
           }
           catch (Exception ex)
           {}}

解决方案

Please add following code in your gridview.

<asp:GridView ID="gdvId" runat="server">
       <Columns>
       </Columns>
       <EmptyDataTemplate>
           No resources found.
       </EmptyDataTemplate>
   </asp:GridView>


这篇关于当数据库返回null值时,如何在gridview中显示正确的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆