Telerik Radgrid not displaying in the browser
Asked Answered
V

2

6

Telerik Rad control just displaying as solid straight line in the browser. But in the Visual studio design it displaying properly.

<telerik:RadGrid ID="RadGrid1" runat="server" 
        onneeddatasource="RadGrid1_NeedDataSource">
    <MasterTableView ShowHeadersWhenNoRecords="false" AutoGenerateColumns="true">
   <NoRecordsTemplate>
     <div>There are no records to display</div>
   </NoRecordsTemplate>
 </MasterTableView>

    </telerik:RadGrid>

Can some please help me on this

Viscid answered 14/3, 2011 at 17:27 Comment(1)
Do you have any data in the datasource? If you do a "view source" when the datasource is empty can you see the div present?Nidia
M
8

If the datasource of "RadGrid1" is Nothing/Null the control is effectively not bound even if databind() is called. An empty collection can be bound to the control in order for the NoRecordsTemplate to be displayed.

In VB.net:
RadGrid1.DataSource = new Object() {}

In C#:

RadGrid1.DataSource = new object[] { };
Mccaslin answered 25/5, 2011 at 4:15 Comment(0)
C
0

There are a few things you need to setup first in order to display no data template, first you need an actual data source that returns null or empty, if you are just doing this for checking purpose and want to avoid an actual data source then the code provided by ItsPete is good. Also you need to place EnableNoRecordsTemplate="true" in the MasterTableView tags.

Take a look at this code.

    <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" 
    DataSourceID="SqlDataSource1">
<MasterTableView EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="false" 
        AutoGenerateColumns="False" datakeynames="ID" datasourceid="SqlDataSource1">
<NoRecordsTemplate>
No Data Found.
</NoRecordsTemplate>
    <Columns>
        <telerik:GridBoundColumn DataField="ID" DataType="System.Int32" 
            DefaultInsertValue="" HeaderText="ID" ReadOnly="True" SortExpression="ID" 
            UniqueName="ID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="NAME" DefaultInsertValue="" 
            HeaderText="NAME" SortExpression="NAME" UniqueName="NAME">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="PASSWORD" DefaultInsertValue="" 
            HeaderText="PASSWORD" SortExpression="PASSWORD" UniqueName="PASSWORD">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="DEPARTMENT" DefaultInsertValue="" 
            HeaderText="DEPARTMENT" SortExpression="DEPARTMENT" UniqueName="DEPARTMENT">
        </telerik:GridBoundColumn>
    </Columns>
</MasterTableView>
</telerik:RadGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:Conn %>" 
    SelectCommand="SELECT * from Users WHERE ID = '0'">
</asp:SqlDataSource>

Data columns here are irrelevant (Just example). For more information about RadGrid, visit "Tips for using the RadGrid - Empty Data Message".

Cornia answered 25/5, 2011 at 5:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.