CodeSmith Community
Your Code. Your Way. Faster!

Export to excel in AJAX

Latest post 08-27-2007 2:12 PM by TNT. 6 replies.
  • 08-21-2007 3:13 AM

    Export to excel in AJAX

    i activate export to excel but it turned out to be an error pop up message when i clicked the excel image button saying something about rendering tag.

    i put the entitygridview in an updatepanel.

    is it because of it

    TIA

     

    Regards

    Oki 

     

     

     

    Filed under:
    • Post Points: 35
  • 08-21-2007 5:36 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: Export to excel in AJAX

    Oki,

    Export LinkButton needs to be registered as postback control (its' ID is lnkExport):

        private void registerPostBack()
        {
            System.Collections.Generic.IList<Control> list = FormUtil.FindControls(GridView1, "lnkExport");

            if (list.Count > 0)
            {
                LinkButton lnkExport = list[0] as LinkButton;
                ScriptManager sm = ScriptManager.GetCurrent(this.Page);
                if (sm != null)
                    sm.RegisterPostBackControl(lnkExport);
            }
        }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 08-21-2007 7:24 PM In reply to

    Re: Export to excel in AJAX - SOLVED!

    it works fine.

    Thanks

    Oki 

    • Post Points: 35
  • 08-27-2007 12:10 PM In reply to

    • TNT
    • Not Ranked
    • Joined on 03-08-2007
    • Posts 3
    • Points 45

    Re: Export to excel in AJAX - SOLVED!

    I follow the posts below with using registerPostback().  It works well in case the EntityGridView's datasource is Table DataSource.  But, I meet the same problem when the EntityGridView uses Table DataSource without registerPostback().   It seem that the 'lnkExport' cannot be registered when DataSource is generated from View.

     

    Do you have any idea?
    • Post Points: 35
  • 08-27-2007 1:18 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,880

    Re: Export to excel in AJAX - SOLVED!

    TNT,

    I couldn't replicate the problem you're experiencing. I tried the the following from the Northwind and it worked as expected:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
     <ContentTemplate>

      <data:EntityGridView ID="GridView1" runat="server"   
        DataSourceID="AlphabeticalListOfProductsDataSource"
        AllowMultiColumnSorting="false"
        DefaultSortColumnName=""
        DefaultSortDirection="Ascending" 
        ExcelExportFileName="Export_Categories.xls"   
        AutoGenerateColumns="true" 
       >
       <Columns>
       </Columns>
      </data:EntityGridView>
     </ContentTemplate>
     </asp:UpdatePanel> 

        <data:AlphabeticalListOfProductsDataSource runat="server" ID="AlphabeticalListOfProductsDataSource"
            SelectMethod="GetPaged"
            EnablePaging="true"
            EnableSorting="true"
        >   
        </data:AlphabeticalListOfProductsDataSource>

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 08-27-2007 2:00 PM In reply to

    • TNT
    • Not Ranked
    • Joined on 03-08-2007
    • Posts 3
    • Points 45

    Re: Export to excel in AJAX - SOLVED!

    Hi Mike123,

     After checking a lot, I find that:

    1. launching page, click export to excel, it OK; but,

    2. If I click the 'Select' button on row first, the problem (an error pop up message), then click the 'Select' button again, it is OK.  After that, when click the 'Export' to Excel, I meet the problem;  Or, after I use the filter data by search panel, the function of Exporting to Excel cannot be used any more because of the error message.

    Here is my source code.

    <data:GridViewSearchPanel ID="gvspOrder" runat="server" GridViewControlID="egvOrder" Visible="true"
                OnSearchButtonClicked="gvspOrder_SearchButtonClicked" >
                <FieldsToExclude>
                    <data:Field Value="O_ID" />
                    <data:Field Value="FundingSourceID" />
                    <data:Field Value="IsLockedMoney" />
                    <data:Field Value="XID" />
                    <data:Field Value="AuthCode" />
                </FieldsToExclude>
            </data:GridViewSearchPanel>
            <br />
            <data:EntityGridView ID="egvOrder" runat="server"           
                AutoGenerateColumns="False"                   
                AutoGenerateSelectButton="True"
                OnSelectedIndexChanged="egvOrder_SelectedIndexChanged"
                DataSourceID="OrderDataSource" DataKeyNames="OId"
                AllowMultiColumnSorting="False"
                DefaultSortColumnName="Date" DefaultSortDirection="Ascending"   
                ExcelExportFileName="Export_Order.xls" OnExcelBeforeFormat="egvOrder_ExcelBeforeFormat"
                AllowExportToExcel="False" ExportToExcelText="Excel" ExportToolTip="Click here to export Excel"
                AllowSorting="True" CellPadding="4" ForeColor="#333333" GridLines="Both"
                PageSelectorPageSizeInterval="10"            
                SortAscImageUrl="Images/sortascending.gif" SortDescImageUrl="Images/sortdescending.gif"         
                >
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <Columns>
                    <asp:CommandField ShowSelectButton="True" ShowEditButton="True" Visible="False"/>               
                    <asp:BoundField DataField="Code" HeaderText="Customer Code" SortExpression="Code"  />
                    <asp:BoundField DataField="OrderAction" HeaderText="Action" SortExpression="OrderAction"  />
                    <asp:BoundField DataField="Symbol" HeaderText="Symbol" SortExpression="Symbol"  />               
                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity"  />
                    <asp:BoundField DataField="MatchedQuantity" HeaderText="Matched Quantity" SortExpression="MatchedQuantity"  />
                    <asp:BoundField DataField="OrderType" HeaderText="Matched Quantity" SortExpression="OrderType"  />
                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"  />
                    <asp:BoundField DataField="Fee" HeaderText="Fee" SortExpression="Fee"  />
                    <asp:BoundField DataField="MatchedAmount" HeaderText="Matched Amount" SortExpression="MatchedAmount"  />
                    <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date"  />
                    <asp:BoundField DataField="OrderStatus" HeaderText="Status" SortExpression="OrderStatus"  />
                    <asp:BoundField DataField="FundingSourceId" HeaderText="Funding Source ID" SortExpression="FundingSourceID" Visible="False" />
                    <asp:BoundField DataField="FundingSourceName" HeaderText="Funding Source Name" SortExpression="FundingSourceName"  />
                    <asp:BoundField DataField="XId" HeaderText="XID" SortExpression="XID" Visible="False" />

                    <asp:TemplateField HeaderText="Matched Details">
                        <ItemTemplate>
                            <asp:GridView ID="egvMatch" runat="server" AllowMultiColumnSorting="false" OnSorting="egvMatch_Sorting"
                                AutoGenerateColumns="False" DataKeyNames="MId" DataSource='<%#GetTrasnl(Convert.ToInt32(Eval("OId"))) %>'
                                ExcelExportFileName="Export_OrderMatch.xls" BackColor="White"
                                BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
                                GridLines="None">
                                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="White" />
                                <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                                <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                                <RowStyle Height="18pt" BackColor="#DEDFDE" ForeColor="Black" />
                                <Columns>

                                    <asp:BoundField DataField="MatchId" HeaderText="Match Id" SortExpression="MatchID" />
                                    <asp:BoundField DataField="Quantity" HeaderText="Quantity" SortExpression="Quantity" />
                                    <asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
                                    <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
                                    <asp:BoundField DataField="Time" DataFormatString="{0:g}" HeaderText="Time" HtmlEncode="False"
                                        SortExpression="Time" />
                                    <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" Visible="False"/>
                                </Columns>
                                <EmptyDataTemplate>
                                    <b>No Matching Found!</b>
                                </EmptyDataTemplate>
                            </asp:GridView>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EmptyDataTemplate>
                    <b>No Order Found!</b>
                </EmptyDataTemplate>
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            </data:EntityGridView>
            <br />      
           
             <br />
            <br />
            <asp:Label ID="lblMessage" runat="server"></asp:Label><br />


            <data:VOrderViewDataSource ID="OrderDataSource" runat="server"
                SelectMethod="GetPaged"
                EnablePaging="True"
                EnableSorting="True"           
            >
                <Parameters>
                    <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />
                    <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
                    <asp:ControlParameter Name="PageIndex" ControlID="egvOrder" PropertyName="PageIndex" Type="Int32" />
                    <asp:ControlParameter Name="PageSize" ControlID="egvOrder" PropertyName="PageSize" Type="Int32" />
                    <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />
                </Parameters>
            </data:VOrderViewDataSource>           
     

    • Post Points: 5
  • 08-27-2007 2:12 PM In reply to

    • TNT
    • Not Ranked
    • Joined on 03-08-2007
    • Posts 3
    • Points 45

    Re: Export to excel in AJAX - SOLVED!

    I have just solved by using registerPostback() in the OnPreRender().

         protected void egvOrder_PreRender(object sender, EventArgs e)
        {
            registerPostBack();
        }
     

    Anyway, thanks your help. 

    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems