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

Showheader always

3 Answers 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wang
Top achievements
Rank 1
Wang asked on 13 Jun 2016, 10:22 AM

Hello,

I want to show grid header always,even there is no datasource or records,here is the code I tried,but the header did't show:

<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"  AllowFilteringByColumn="True" CellSpacing="0" ShowHeader="true">
         <MasterTableView AutoGenerateColumns="false" ShowHeader="true" ShowHeadersWhenNoRecords="true">
                        <Columns>
                            <telerik:GridBoundColumn DataField="BrandName" HeaderText="Brand Name" UniqueName="BrandName">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Model" HeaderText="Model" UniqueName="Model">
                            </telerik:GridBoundColumn>
                            </Columns>
             </MasterTableView>
         </telerik:RadGrid>

 

what should I do?

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 13 Jun 2016, 11:57 AM
Hello,

Could you specify how is the grid populated? I tested the code below on my end and the headers show as expected when 0 records are loaded:
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource" AllowFilteringByColumn="True" CellSpacing="0" ShowHeader="true">
            <MasterTableView AutoGenerateColumns="false" ShowHeader="true" ShowHeadersWhenNoRecords="true">
                <Columns>
                    <telerik:GridBoundColumn DataField="BrandName" HeaderText="Brand Name" UniqueName="BrandName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Model" HeaderText="Model" UniqueName="Model">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable("SELECT Top 0 * FROM Customers");
}

Regards,
Pavlina
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Wang
Top achievements
Rank 1
answered on 15 Jun 2016, 01:44 AM

Thank you very much,

In my project,when page loaded,the grid do not load datasource or databind,when user set the condition of query(like keywords or some else),and click query button on the radtoolbar,I would set the datasource and  databind(); can I use RadGrid1_NeedDataSource event in this case?

0
Pavlina
Telerik team
answered on 15 Jun 2016, 08:32 AM
Hi,

Yes you can use NeedDaatSource in this case you just need to call RadGrid1.Rebind() on button click.The Rebind() method will force the grid to fire NeedDataSource event and populate the control. 

Regards,
Pavlina
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Wang
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Wang
Top achievements
Rank 1
Share this question
or