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

exporting to Excel / one click

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rudy
Top achievements
Rank 1
Rudy asked on 11 Feb 2009, 09:45 AM
hello,
i have a little problem when before exporting to excel i have to rebind my radgrid. The result is that i need to click 2 times on the "Export to Excel" button, and i can't hide the "CommandItem"
(gridBooth.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None)
because if i do this the "Export to Excel" button disappears...
in this way in my excel i see the icons for exporting...

how can i bypass the second click??
this is my code...
 protected void btnExportXLS_Click(object sender, EventArgs e)
        {
            _stand.GetAll();

            FormatColumnsForExport();

            gridBooth.Rebind();

            gridBooth.ExportSettings.ExportOnlyData = false;
            gridBooth.ExportSettings.IgnorePaging = true;
            //gridBooth.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
            gridBooth.ExportSettings.FileName = "ExportStands.xcl";
            gridBooth.ExportSettings.OpenInNewWindow = true;
            gridBooth.MasterTableView.ExportToExcel();
        }

        private void FormatColumnsForExport()
        {
            foreach (GridColumn col in gridBooth.MasterTableView.Columns)
                gridBooth.MasterTableView.Columns.FindByUniqueName(col.UniqueName).Visible = true;

            gridBooth.MasterTableView.Columns.FindByUniqueName("Espositore").Visible = false;
            gridBooth.MasterTableView.Columns.FindByUniqueName("statusimg").Visible = false;

        }

ascx:
<telerik:RadGrid ID="gridBooth" runat="server" AllowPaging="True" AllowCustomPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" GridLines="None"  EnableAJAX="true"
                OnNeedDataSource="gridBooth_NeedDataSource"  OnSortCommand="RadGrid1_SortCommand"
                OnPageIndexChanged="gridBooth_PageIndexChanged" Height="500px"
                                onitemcreated="gridBooth_ItemCreated" Skin="Vista"
                onexcelexportcellformatting="gridBooth_ExcelExportCellFormatting">
                <PagerStyle Mode="NextPrevAndNumeric" />
                
                   <MasterTableView CommandItemDisplay="Top">
                   <CommandItemTemplate>
                        <table width="100%" cellpadding=2 cellspacing=2 border=0>
                       <tr>
                           <td class="normal" width="25%" align=center><asp:LinkButton ID="btnExportXLS" runat=server CausesValidation=false OnClick="btnExportXLS_Click"><img src="/images/xls.jpg" border=0 />&nbsp;Totale</asp:LinkButton></td>
                           <td class="normal" width="25%" align=center><asp:LinkButton ID="btnExportXLS_Filtered" runat=server CausesValidation=false  OnClick="btnExportXLS_Filter"><img src="/images/xls.jpg" border=0 />&nbsp;Filtrati</asp:LinkButton></td>
                           <td class="normal" width="25%" align=center><asp:LinkButton ID="btnExportCSV" runat=server CausesValidation=false OnClick="btnExportCSV_Click">CSV Totale</asp:LinkButton></td>
                           <td class="normal" width="25%" align=center><asp:LinkButton ID="btnExportCSV_Filtered" runat=server CausesValidation=false OnClick="btnExportCSV_Filter">CSV Filtrati</asp:LinkButton></td>                       
                       </tr>
                       </table>
                    </CommandItemTemplate>

                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn AllowFiltering="False" DataField="HallName" EmptyDataText="&amp;nbsp;"
                            HeaderText="Pad." UniqueName="HallName">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridBoundColumn DataField="Name" EmptyDataText="-" HeaderText="Stand"
                            UniqueName="Name">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridTemplateColumn DataField="Quality" HeaderText="Qualità" UniqueName="Quality"
                        SortExpression="Quality">
                        <ItemTemplate>
                            <%# GetQuality(DataBinder.Eval(Container.DataItem, "Quality"))%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="Mq" EmptyDataText="-;" HeaderText="Mq"
                            UniqueName="Mq">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridTemplateColumn DataField="CompanyName" HeaderText="Espositore" UniqueName="Espositore"
                        SortExpression="CompanyName">
                        <ItemTemplate>
                            <%# GetEspositoreLink(DataBinder.Eval(Container.DataItem, "CompanyName"), DataBinder.Eval(Container.DataItem, "BookerId"))%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="CompanyName" EmptyDataText="-" visible=false HeaderText="Espositore"
                        UniqueName="EspositoreData">
                        </telerik:GridBoundColumn>                      
                        
                        <telerik:GridTemplateColumn DataField="CreationDate" HeaderText="Data Pren." UniqueName="CreationDate"
                        SortExpression="CreationDate">
                        <ItemTemplate>
                            <%# GetData(Container.DataItem)%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="ExpireDate" EmptyDataText="-" HeaderText="Scadenza"
                            UniqueName="ExpireDate">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridTemplateColumn DataField="ProductId" HeaderText="Tipo"
                        UniqueName="ProductId" SortExpression="ProductId">
                        <ItemTemplate>
                            <%# GetProductName(DataBinder.Eval(Container.DataItem, "ProductId"))%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="Price"  EmptyDataText="0" HeaderText="Prezzo"
                            UniqueName="Price">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridBoundColumn DataField="Discount" EmptyDataText="0" HeaderText="Sconto"
                            UniqueName="Discount">
                        </telerik:GridBoundColumn>
                        
                        <telerik:GridTemplateColumn DataField="Status" HeaderText="Stato" UniqueName="statusimg"
                        SortExpression="Status">
                        <ItemTemplate>
                            <%# GetStatusImages(DataBinder.Eval(Container.DataItem, "Status"))%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridTemplateColumn DataField="Status" visible=false UniqueName="statustext" HeaderText="Stato">
                        <ItemTemplate>
                            <%# GetStatusText(DataBinder.Eval(Container.DataItem, "Status"))%>
                        </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        
                        <telerik:GridBoundColumn DataField="EventName" EmptyDataText="&amp;nbsp;" HeaderText="Evento"
                            UniqueName="EventName">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowColumnsReorder="True">
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                </ClientSettings>
                <FilterMenu EnableTheming="True">
                    <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
                </FilterMenu>
                <sortingsettings sorttooltip="Clicca per ordinare" />
            </telerik:RadGrid>




1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 16 Feb 2009, 08:00 AM
Hi Rudy,

When ExportSettings.IgnorePaging  is set to true, RadGrid will rebind by itself, so you don't need the call to the grid's rebind method. Furthermore, in order to hide the ExportToExcell button, you should set ExportSettings.ExportOnlyData = true. The latter will also make the grid rebind by itself.

Hope this helps.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Rudy
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or