| Radgrid Empty Template For Empty Datasource |
|
Whenever using a Radgrid control there is always a possibility that the datasource return an empty record dataset. When the datasource is null or empty a user need to be informed with a message indicating as such. To show such messages you need to enable the NoRecordsTemplate property of the Radgrid. When the NoRecordsTemplate is set to true it will show the empty template if there are no data return from the datasource. Also if you would like to display the header when there are no data in the datasource you can set the property ShowHeadersWhenNoRecords to true. EXAMPLES: <telerik:RadGrid ID="gridEntries" Width="1100px" runat="server" AutoGenerateColumns="false" Skin="Sunset" AllowMultiRowSelection="false" OnNeedDataSource="gridEntries_NeedDataSource" OnDeleteCommand="gridEntries_DeleteCommand" OnItemCommand="gridEntries_ItemCommand"> <ClientSettings> </ClientSettings>
<MasterTableView HierarchyDefaultExpanded="false" EditMode="PopUp" HierarchyLoadMode="Client" ShowHeadersWhenNoRecords="false" EnableNoRecordsTemplate="true" DataKeyNames="EntryID" CommandItemDisplay="None"> <NoRecordsTemplate> <div>There are no records to display</div> </NoRecordsTemplate> <Columns> <telerik:GridBoundColumn DataField="SignInDateTime" DataFormatString="{0:dd/MM/yyyy}" ItemStyle-Width="60" HeaderText="Date"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="SignInDateTime" DataFormatString="{0:HH:mm}" ItemStyle-Width="30" HeaderText="Time"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Name" ItemStyle-Width="150" HeaderText="Name"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ContactDetails" ItemStyle-Width="100" HeaderText="Contact Details"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="NumberOfIndividuals" ItemStyle-Width="100" HeaderText="No of Individuals"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="reasonForVisit" ItemStyle-Width="400" HeaderText="Reason For Visit"> </telerik:GridBoundColumn> <telerik:GridButtonColumn CommandName="Delete" Text="Sign Out" UniqueName="DeleteColumn" ButtonType="PushButton" ItemStyle-Width="50"> </telerik:GridButtonColumn> </Columns> </MasterTableView> <HeaderStyle Font-Bold="true" HorizontalAlign="Center" /> <ItemStyle HorizontalAlign="Left" /> <AlternatingItemStyle HorizontalAlign="Left" /> </telerik:RadGrid>
|