找不到记录消息 [英] No Record Found Message

查看:69
本文介绍了找不到记录消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们将数据搜索到数据库时,如何显示No Record Found消息,如果找到记录,则在Grid View中显示相关数据,如果找不到Data,则显示No Record Found消息?

How to display "No Record Found" message when we search the data into the Database, if the record is found then related data shows in Grid View and if the Data is not found then display a "No Record Found" message ?

推荐答案

Gridview具有名为EmptyDataText的属性..将其设置为您要显示的任何消息...



Gridview has property called EmptyDataText .. set it to whatever message you want to display...

 <asp:gridview id="grdViewKeyType" runat="server" allowpaging="True" autogeneratecolumns="False" xmlns:asp="#unknown">
                                BackColor="White" BorderColor="#999999" BorderStyle="Solid" 
                    CellPadding="5" CellSpacing="1"
                                CssClass="Grid" 

EmptyDataText="No Records found" 

....

</asp:gridview>


请参阅gridview中空数据模板的以下链接

http://msdn.microsoft.com/en-us/library/syst em.web.ui.webcontrols.gridview.emptydatatemplate.aspx [ ^ ]
see below link for empty data template in gridview
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.emptydatatemplate.aspx[^]


你有另一个数据表选项,



you have another option with datatable,

DataTable dt = new DataTable();
            try
            {
                Con_Open();
                cmd = new SqlCommand("select * from Stu", con);
                dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    dt.Columns.Add(new DataColumn("Reg No"));
                    dt.Columns.Add(new DataColumn("Name"));
                    dt.Columns.Add(new DataColumn("Mark1"));
                    dt.Columns.Add(new DataColumn("Mark2"));
                    dt.Columns.Add(new DataColumn("Mark3"));
                    while (dr.Read())
                    {
                        DataRow temp;
                        temp = dt.NewRow();
                        temp[0] = (System.Convert.IsDBNull(dr[0]) ? "" : dr[0].ToString());
                        temp[1] = (System.Convert.IsDBNull(dr[1]) ? "" : dr[1].ToString());
                        temp[2] = (System.Convert.IsDBNull(dr[2]) ? "" : dr[2].ToString());
                        temp[3] = (System.Convert.IsDBNull(dr[3]) ? "" : dr[3].ToString());
                        temp[4] = (System.Convert.IsDBNull(dr[4]) ? "" : dr[4].ToString());
                        dt.Rows.Add(temp);
                    }
                    cmd.Dispose();
                    dr.Close();
                    con.Close();
                }
                else
                {

                    dt.Columns.Add(new DataColumn("Records"));
                    DataRow temp;
                    temp = dt.NewRow();
                    temp[0] = "No Records Found!!";
                    dt.Rows.Add(temp);
                }             
            }





问候

sarva



regards
sarva

这篇关于找不到记录消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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