Showheader always

4 posts, 0 answers
  1. Wang
    Wang avatar
    42 posts
    Member since:
    Oct 2011

    Posted 13 Jun Link to this post

    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?

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 13 Jun Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Wang
    Wang avatar
    42 posts
    Member since:
    Oct 2011

    Posted 14 Jun in reply to Pavlina Link to this post

    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?

  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 15 Jun Link to this post

    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.
Back to Top