This is a migrated thread and some comments may be shown as answers.

ShowHeadersWhenNoRecords

5 Answers 218 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 28 Oct 2008, 11:22 PM
Anyone care to tell me what I am missing?  I tried everything I could find and still cannot get the empty grid to show with my no records template.  I just get a small line where headers should be.  Everything displays fine when data is in grid.

        <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1">  
            <MasterTableView DataSourceID="SqlDataSource1" ShowHeadersWhenNoRecords="true">  
                <NoRecordsTemplate> 
                    No positions are currently listed, please check back at a later time.  
                </NoRecordsTemplate> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridBoundColumn DataField="employment_id"   
                    HeaderText="..." UniqueName="column">  
                </telerik:GridBoundColumn> 
            </Columns> 
            </MasterTableView> 
            <FilterMenu EnableTheming="True">  
                <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
            </FilterMenu> 
        </telerik:RadGrid> 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2008, 04:02 AM
Hello Sam,

The NoRecordsTemplate should dispaly  when there are no records in the grid but possibly if you set the DataSource as shown below then the template will not display.
RadGrid1.DataSourceID=String.Empty or RadGrid1.DataSourceID="" 

You can try the following code instead.
RadGrid1.DataSource = new string[] { }; 

Thanks
Princy.
0
Dave
Top achievements
Rank 1
answered on 29 Oct 2008, 11:46 AM
Thank for the response Princy, although I have to admit I don't quite understand it.  I've given the grid a datasourceID that has the potential to return no records based on a data paramater.  In fact, I ensure it returns no records due to a date I am throwing at it from a session variable.

I did change my code and threw it empty strings, etc. like you suggested and cannot get the empty data grid to show.
0
Accepted
Sebastian
Telerik team
answered on 29 Oct 2008, 01:40 PM
Hello Sam,

Here is a little trick which will render the NoRecords template when there is no value passed for the SelectParameter of the data source control:

            <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
            <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" 
                Skin="Office2007" ShowStatusBar="true" GridLines="None" Width="95%">  
                <MasterTableView Width="100%" /> 
            </telerik:RadGrid> 
            <br /> 
            <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                ProviderName="System.Data.SqlClient" SelectCommand="SELECT TOP 10 CustomerID, CompanyName, ContactName, ContactTitle, Address, PostalCode FROM Customers WHERE CustomerID = @CustomerID" 
                runat="server">  
                <SelectParameters> 
                  <asp:Parameter Name="CustomerID" Type="string" DefaultValue="*" /> 
                </SelectParameters>     
             </asp:SqlDataSource> 

The idea is to set DefaultValue for the corresponding select parameter which is not in the list of valid values in the source. Thus the no records message should be rendered as expected.

Best regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Dave
Top achievements
Rank 1
answered on 29 Oct 2008, 05:17 PM
Thanks Stephen, this made a lot more sense (while at the same time making no sense at all).  It appears that you are saying if the default select query does not have a valid parameter passed to it for the initial query then it returns nothing at all, instead of a no records found type response.  I tested this theory by first adding the default value as you suggested, then changing my VB code to give a date far into the future and was able to get the empty grid.

No idea why that is necessary, but I assume it has to do with the way the SQL control functions.  Thanks again for the response.
0
Dave
Top achievements
Rank 1
answered on 29 Oct 2008, 05:17 PM
disregard, double post.
Tags
Grid
Asked by
Dave
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dave
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or