在网格视图中访问数据 [英] Access data in Grid View

查看:106
本文介绍了在网格视图中访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,其中我正在显示来自sql server.now的数据.在我的UI上,当网格视图中没有要显示的数据时,我想显示文本"No Data Available"(即没有可用的数据)在网格视图中显示数据为空.问题是我应该如何赋予gridview为空的条件?

我使用了此代码,但未在标签中显示文本.

i have a gridview in which i am displaying data from sql server.now on my UI i want to display a text "No Data Available" when there is no data to be shown in the grid view i.e. the table from which im displaying data in grid view is empty. the problem is how should i give the condition that gridview is empty?

i used this code but its not displaying the text in the label.

SqlCommand cmd = new SqlCommand("select * from Requests", new SqlConnection(myConnectionString));

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        DataSet ds = new DataSet();

        da.Fill(ds);
        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                lblError.Text = "Dataset table contains data";
            }
        }

        else
        {
            lblError.Visible = true;
            lblError.Text = "Dataset does not contains data";
        }

推荐答案


我对你的病情做了些小改动.请检查此

Hi
I made a small change in your condition. Please check this

da.Fill(ds);
         if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
         {
             lblError.Text = "Dataset table contains data";
         }
         else
         {
             lblError.Visible = true;
             lblError.Text = "Dataset does not contains data";
         }


您可以通过两种方式来实现.

1. EmptyDataText属性.
2. DataSetDataTable行计数.

请在没有数据或没有数据时检查 Asp.net显示gridview标头 [ ^ ].
You can do it in two ways.

1. EmptyDataText property.
2. DataSet or DataTable row counts.

Please check Asp.net show gridview header when there is no data or empty[^] for the clear example.


这篇关于在网格视图中访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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