Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
I have a problem in datagridview control while working with desktop application.
I use data set to bind this datagridview.If dataset is not empty it display all records in datagridview.
Suppose Data set is empty,I want give message to the user "No Record founds" and display it in the single row of datagridview.

Please Help me.

Thanks in Advance..



Randeep Chauhan...
Posted
Updated 23-May-11 1:02am
v4
Comments
CS2011 23-May-11 7:14am    
See my soluation. Hope it helps.

 
Share this answer
 
Comments
Dalek Dave 23-May-11 6:53am    
Nice Link.
Try following.Basically dataset.fill returns number of rows returned by your query

int rows = DatasetName.fill(dataadapter,"tablename");
if(rows <= 0)
{
  //Add a row to data grid and display your msg
}
else
{
  //do what needs to be done
}
 
Share this answer
 
v2
XML
<EmptyDataTemplate>
                                                <table width="100%">
                                                    <tr>
                                                        <td class="ob_gNRM" style="height: 40px; text-align: center">
                                                            There are no records available.
                                                        </td>
                                                    </tr>
                                                </table>
                                            </EmptyDataTemplate>
 
Share this answer
 
Comments
skantg 23-May-11 7:30am    
This one is perfect without any server side coding.
emptyDataTemplate take care of blank grid by itself.
Hi...

You can put <emptydatatemplate> inside the grid view control

and give you message inside this tag like

<emptydatatemplate>No Record founds


This will help you...

Try it..
 
Share this answer
 
v2
Comments
Randeep Chauhan 23-May-11 6:50am    
But i am working in window application not web application


Thanks for reply
Randeep Chauhan
Deepthi Aravind 23-May-11 7:12am    
sorry..its my mistake..
<asp:gridview id="GridView1" datakeynames="Id" emptydatatext="No Records" showheader="true" runat="server" autogeneratecolumns="False" allowpaging="True" xmlns:asp="#unknown">

/* Bind Your GridView  with DataSet and set [EmptyDataText]="No Record"  </asp:gridview>
 
Share this answer
 
I had st1 as the datgrid...



If st1.RecordCount = -1 Then
GoTo TrySt1Rd1
Else
GoTo GotSt
End If



The object returned a -1 if there were no records
 
Share this answer
 

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