如何在C#中显示datagridview的空数据文本 [英] how to display empty datatext for datagridview in c#

查看:372
本文介绍了如何在C#中显示datagridview的空数据文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用某种条件在C#.NET中显示datagridview

##############这是我的代码#############


i am using some condition to display the datagridview in C# .NET

##############This is my code############


con.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(" select * from studentdetails where name  like  + '" + txtfilter.Text + "' + '%' ",con);
            DataTable t = new DataTable();
            da.Fill(t);
            if (t.Rows.Count > 0)
            {
                lblnone.Visible = false;
                dataGridView1.DataSource = t;
            }
            else
            {
               
            }
            
            con.Close();



############################################# ######
如何使else条件显示没有记录"



############## ########## ############# ###################
how to give the else condition to display "NO RECORDS FOUND"

推荐答案



如果您在没有数据时显示找不到记录"文本,请在else块中.

你可以这样,
1.
Hi,

If you are looking displaying the "No records found" text when there is no data,in the else block.

You can do it like,
1.
<EmptyDataTemplate>
No Data Available
</EmptyDataTemplate>



在您的datagrid视图声明中.



2.



in your datagrid view declaration.

or

2.

<asp:GridView runat="server" ID="dgvdatagridview" Width="100%".....>
    EmptyDataText="there is no data for this request"





3.一个不可见的标签,将该文本设置为所需的文本,并使其在else块中可见.


4.如果要显示标题,可以将数据行绑定到该数据表,然后将其绑定到datagridview.


希望这会有所帮助.



or

3.A label that is invisible and set that text to the required text and make it visible in else block.

or
4.If you want a header tobe shown, you can bind a datarow to that datatable and bind it to the datagridview.


Hope this helps.


这篇关于如何在C#中显示datagridview的空数据文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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