Click here to Skip to main content
15,878,953 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi all,

i am working on wpf datagrid control.

if no records i want to display the message
"No records found"

i want to display in datagrid only.

how can i do?

let me know

thanks and regards...
Posted
Updated 23-Jul-12 2:25am
v2
Comments
[no name] 23-Jul-12 9:03am    
Well go right ahead and do that.

Try this:
C#
if (Gridview1.Rows.Count > 0)
    {
       //Bind your grid here
       lblRecordNotFound.Visible = false;
    }
    else
    {
        lblRecordNotFound.Visible = true; // label for "Record Not Found"
    }
 
Share this answer
 
Comments
Vani Kulkarni 23-Jul-12 6:44am    
Hi Prasad, will this work in case of WPF datagrid control too?
U@007 23-Jul-12 8:24am    
i want to display in datagrid only.
You might find following link helpful:
show-no-record-found-meesage-on-wpf-datagrid-when-its-empty[^]
 
Share this answer
 
Count records, if 0 hide your grid and display a label instead.
 
Share this answer
 
Comments
U@007 23-Jul-12 8:24am    
i want to display in datagrid only.
StianSandberg 23-Jul-12 8:32am    
what do you mean?
U@007 23-Jul-12 8:54am    
i want to disyplay the message inside the datagrid
i think this following gives your solution
you can read artical
Quote:
How To Give message to user that "No Record found" in datagridview control when dataset is empty

in code project


http://stackoverflow.com/questions/4687414/show-no-record-found-meesage-on-wpf-datagrid-when-its-empty[^]

also


http://social.msdn.microsoft.com/Forums/en/wpf/thread/433c8843-848b-431a-93bb-37a4f6642e27[^]
 
Share this answer
 
Comments
U@007 23-Jul-12 8:24am    
i want to display in datagrid only.
rizwan muhammed khan gouri 25-Jul-12 2:09am    
IF YOUR DATA SOURCE IS EMPTY THAN YOU CAN USED THIS PROPERTY FOR DISPLAY NO RECORD FOUND
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" EmptyDataRowStyle-Font-Bold="true" EmptyDataRowStyle-BorderColor="Aqua" EmptyDataText="nO rECORD fOUND" Height="" Width="">
<alternatingrowstyle backcolor="White">
<columns>
Hi,
try this:
C#
// Here dt is your data-table
if(dt.Rows.Count>0){
    DataGrid1.DataSource=dt;
    DataGrid1.DataBind();
}
else{
    dt.Rows.Add();
    DataGrid1.DataSource=dt;
    DataGrid1.DataBind();
    DataGrid1.Items[0].Visible=false;
    //lblMsg.Text="No records Found.";
}


This will display a empty datagrid if the rows are not there. For a message take a label below that and set the text if DataGrid is Empty(I commented that line).

--Amit
 
Share this answer
 
Comments
U@007 23-Jul-12 8:53am    
this is wpf datagrid yar!
Hi,

if you want to display empty message in datagrid, i think its not possible. instead use ASP.NET GridView. you will get "EmptyDataText" property. set that property to your message text. You do not find much difference in performance or functionality between these two.

C#
GridView1.EmptyDataText="No Records Found";


hope it helps.
 
Share this answer
 
Comments
U@007 23-Jul-12 8:52am    
this is wpf datagrid yar!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900