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

CommandItemDisplay shows two headers

4 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 11 Oct 2013, 05:54 AM
Hi,

I'm using the asp Grid to bring back some very simple data using Telerik.Web.UI 2013.1.403.40

I have a problem where if I enable MasterTableView's CommandItemDisplay to anything other than None, it displays two header rows.

(I've attached a screenshot to demonstrate my issue.)


Here's my markup:

<rad:RadGrid runat="server" ID="grdGroupLeaderReport" AutoGenerateColumns="False">
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowAddNewRecordButton="False" ShowRefreshButton="False" ShowExportToExcelButton="True" />
        <Columns>
            <rad:RadGridBoundColumn DataField="Id" UniqueName="Id" HeaderText="Booking Id">
                <HeaderStyle Width="110px"></HeaderStyle>
                <ItemStyle HorizontalAlign="Right"></ItemStyle>
            </rad:RadGridBoundColumn>
                <rad:RadGridBoundColumn DataField="FirstName" UniqueName="FirstName" HeaderText="First Name">
                <HeaderStyle Width="150px"></HeaderStyle>
            </rad:RadGridBoundColumn>
        </Columns>
    </MasterTableView>
</rad:RadGrid>


And here's code behind to bind it (the data source is a DataTable):

grdGroupLeaderReport.DataSource = rc.GroupLeaderReport();
grdGroupLeaderReport.DataBind();

I need to display the Export to Excel button - and each time I enable that toolbar it shows up twice. Where am I going wrong? Please help! (See attached screenshot at bottom of post for an example.)



Also - this is less important - with the BoundColumn the header text is never picked up. I have to set it programmatically in the ItemDataBound event  this is quit annoying however, I can live with this, but why does it happen, am I missing something here too?

void grdGroupLeaderReport_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                var header = (GridHeaderItem)e.Item;
                header["Id"].Text = @"Booking No.";
                header["FirstName"].Text = @"First Name";
            }
        }

Thank you in advance for taking the time to look at this.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Oct 2013, 06:41 AM
Hi Alex,

It is not an expected behavior.Make sure you are binding the radgrid using Advanced Data-binding (using NeedDataSource event). Below is a sample code snippet that i tried which works fine at my end.

ASPX:
<rad:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="False" OnItemDataBound="RadGrid1_ItemDataBound"
    OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView CommandItemDisplay="Top">
        <CommandItemSettings ShowAddNewRecordButton="False" ShowRefreshButton="False" ShowExportToExcelButton="True" />
        <Columns>
            <rad:GridBoundColumn DataField="CustomerID" UniqueName="CustomerID">
            </rad:GridBoundColumn>
            <rad:GridBoundColumn DataField="CompanyName" UniqueName="CompanyName">
            </rad:GridBoundColumn>
        </Columns>
    </MasterTableView>
</rad:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand("SELECT CustomerID, CompanyName FROM Customers", conn);
 
        DataTable myDataTable = new DataTable();
 
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
 
        RadGrid1.DataSource = myDataTable;
    }
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridHeaderItem)
        {
            GridHeaderItem header = (GridHeaderItem)e.Item;
            header["CustomerID"].Text = @"Booking No.";
            header["CompanyName"].Text = @"First Name";
        }
    }

Thanks,
Princy
0
Alex
Top achievements
Rank 1
answered on 11 Oct 2013, 08:04 AM
Hi Princy,

Thanks for the reply, I've copied your code exactly however I still have the same issue.

I've also updated Telerik.Web.dll to 2013.2.717.40

The HTML that's rendered by page is as follows;

Header 1 - just an html table
<table class="rgMasterTable rgClipCells" id="ctr470_Arrival_Reports_View_grdGroupLeaderReport_ctl00_TopPager" style="width: 100%; table-layout: fixed; overflow: hidden; empty-cells: show;">
.. 
</table>


Header 2 - an html table nested within 2 divs
<div class="rgHeaderWrapper">
          <div id="ctr470_Arrival_Reports_View_grdGroupLeaderReport_GridHeader" class="rgHeaderDiv" style="overflow: hidden;">
          <table class="rgMasterTable rgClipCells rgClipCells" id="ctr470_Arrival_Reports_View_grdGroupLeaderReport_ctl00_Header" style="width: 100%; table-layout: fixed; overflow: hidden; empty-cells: show;">
              ...
          </table>
     </div>
</div>


I don't know if the table ID's give you any hints as to why this happens? One is "TopPager" and the other is "Header"

Table 1: ctr470_Arrival_Reports_View_grdGroupLeaderReport_ctl00_TopPager
Table 2: ctr470_Arrival_Reports_View_grdGroupLeaderReport_ctl00_Header

Other than that my code is identical to yours (with the exception of <HeaderStyle> for the width):

ASPX:
<rad:RadGrid runat="server" ID="grdGroupLeaderReport" AutoGenerateColumns="False" OnItemDataBound="grdGroupLeaderReport_ItemDataBound" OnNeedDataSource="grdGroupLeaderReport_NeedDataSource">
    <MasterTableView CommandItemDisplay="Top">
        <Columns>
            <rad:GridBoundColumn DataField="Id" UniqueName="Id">
                <HeaderStyle Width="110px"></HeaderStyle>
                <ItemStyle HorizontalAlign="Right"></ItemStyle>
            </rad:GridBoundColumn>
            <rad:GridBoundColumn DataField="FirstName" UniqueName="FirstName">
                <HeaderStyle Width="150px"></HeaderStyle>
            </rad:GridBoundColumn>
        </Columns>
    </MasterTableView>
</rad:RadGrid>


C#:
protected void grdGroupLeaderReport_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridHeaderItem)
            {
                var header = (GridHeaderItem)e.Item;
                header["Id"].Text = @"Booking No.";
                header["FirstName"].Text = @"First Name";
            }
        }
 
        protected void grdGroupLeaderReport_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            String ConnString = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
            SqlConnection conn = new SqlConnection(ConnString);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = new SqlCommand("SELECT Id, FirstName FROM vw_AJF_Intranet_Arrival_Reports_GroupLeader ORDER BY FirstName ASC", conn);
 
            DataTable myDataTable = new DataTable();
 
            conn.Open();
            try
            {
                adapter.Fill(myDataTable);
            }
            finally
            {
                conn.Close();
            }
 
            grdGroupLeaderReport.DataSource = myDataTable;
        }



I'm really stumped as to how to stop the toolbar showing twice. 

Thanks again.
0
Alex
Top achievements
Rank 1
answered on 14 Oct 2013, 05:24 AM
I've narrowed this down to being caused by a DNN wrapper.

Scrolling is enabled by default and cannot be disabled - by forcing no scrolling (by setting ScreenRowNumber) to a high value, this stops the second header being rendered.

Should this bug be logged with DNN?
0
Pavlina
Telerik team
answered on 16 Oct 2013, 08:08 AM
Hello Alex,

The development of the Telerik.DNN.Modules was discontinued since Q2 2012 (version 2011.1.519) in favor of the Telerik providers and modules developed and offered by DNN Corp. You can find more information in the following FAQ section:
http://www.telerik.com/purchase/faqs/telerik-dnn-partnership-qanda.aspx

In case you encounter some issues while implementing RadGrid scrolling in DNN our suggestion is to post your question in the DotNetNuke forums or contact the support of DNN for technical help with our products.

Regards,
Pavlina
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Alex
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or