在网格视图中访问数据

在网格视图中访问数据

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

问题描述

我有一个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";
        }

推荐答案

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";
         }



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

07-23 00:32