如果数据库中没有数据,则发出警报 [英] alert if no data present in database

查看:101
本文介绍了如果数据库中没有数据,则发出警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果数据库中没有产品或者没有产品可供显示,那么想显示没有要显示的产品。

怎么做。

这是我用来显示产品的代码



  private   void  BindGridData()
{
try
{
con.Open();
string menuid =应用程序[ MenuId ]的ToString();
{
string sql = 从rsa_ProductItemTable中选择*,其中MenuId = + menuid;
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
}
}

catch (例外情况)
{
}
finally
{
con.Close();
}
}





请帮帮我。

解决方案

添加如下所示的页脚模板 [ ^ ]

 < ;   FooterTemplate  >  
< asp:标签 可见 =' <%#bool.Parse( (DataList1.Items.Count == 0 )。ToString())%>' runat = se rver ID = lblNoRecord 文字 = 找不到记录! > < / asp:标签 >
< / FooterTemplate >


如果你使用.net框架提供的GridView控件,这很容易实现。



步骤

1.打开gridview的智能标签,在底部选择编辑模板。 (智能标签是顶部带有箭头的小按钮

控件)

2.从下拉列表中选择空数据模板。

3.输入要在gridview的内容区域显示的消息。



您可以设置内容样式,使用图像等。完成后,点击结束编辑完成处理。



如果适用,请不要忘记标记为正确答案..

If no products exists in database or if there is no products to display, then wants to display like 'no products to display'.
How to do that.
This is the code i have used to display products

private void BindGridData()
    {
        try
        {
            con.Open();
            string menuid = Application["MenuId"].ToString();
            {
                string sql = "select * from rsa_ProductItemTable where MenuId=" + menuid;
                SqlCommand cmd = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                DataList1.DataSource = ds;
                DataList1.DataBind();
                }
            }

        catch (Exception ex)
        {
        }
        finally
        {
            con.Close();
        }
        }



Please Help me with this.

解决方案

Add footer template like below [^]

<FooterTemplate>
<asp:Label Visible='<%#bool.Parse((DataList1.Items.Count==0).ToString())%>' runat="server" ID="lblNoRecord" Text="No Record Found!"></asp:Label>
</FooterTemplate>


This is very easy to implement if you are using a GridView control provided by .net framework.

STEPS
1. Open the smart tag of the gridview, at the bottom, select Edit Templates. (The smart tag is the little button with a foward arrow on top
of the control)
2. Select from the dropdownlist, Empty Data Template.
3. Enter a message to display in the content area of the gridview that will come up.

You can style the content, use image and more. After doing that, click on End Editing to finish process.

Give it a go, don't forget to mark as correct answer if it works for you..


这篇关于如果数据库中没有数据,则发出警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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