Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
945
WebExcelExporter not working with WHDG.....
posted

Hello,

I have a WHDG that I'm trying to export via the WebExcelExporter. Below is my code. In Internet Explorer, when i click the button to download to excel, I see that the postback is firing the code but, the file that its trying to give me back is "default.aspx" and not the XLS file. When i try it on FireFox, I get the .XSL file to return but in opening the document, i see an empty grid. How do I send the WHDG as is (with out having to refresh the datasource) on the page to the explorter?

Below is my code.

/*********************** ASPX *************************/

<form id="form1" runat="server">
        <ig:WebScriptManager ID="WebScriptManager1" runat="server" />
        <div>
            <table>
                <tr>
                    <td>
                        <igmisc:WebGroupBox ID="WebGroupBox1" runat="server" Width="295px">
                            <Template>
                                <table>
                                    <tr>
                                        <td style="width:85px;">Start Date : </td>
                                        <td style="width:140px;"><ig:WebDatePicker ID="WebStartDate" runat="server" /></td>
                                        <td style="width:60px"><igtxt:WebImageButton ID="WebImageButton1" runat="server" OnClick="Search" Text="Search"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:85px">End Date : </td>
                                        <td style="width:140px;"><ig:WebDatePicker ID="WebEndDate" runat="server" /></td>
                                        <td style="width:60px"><asp:Button runat="server" ID="btnExport" OnClick="btnExport_Click" /></td>
                                    </tr>
                                </table>
                               
                            </Template>
                        </igmisc:WebGroupBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
                            <Triggers>
                                <asp:AsyncPostBackTrigger ControlID="WebGroupBox1$WebImageButton1" EventName="Click"/>
                            </Triggers>
                            <ContentTemplate>
                                <ig:WebHierarchicalDataGrid ID="WHDG" runat="server" Height="800px" Width="1000px" InitialDataBindDepth="-1" EnableAjax="False" />
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                </tr>
            </table>
        </div>
        <ig:WebExcelExporter ID="WebExcelExporter1" runat="server" />
    </form>

 

/*********************** CS *************************/

public partial class ACDVolume : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                using (XmlDataSource xmlDataSource = new XmlDataSource())
                {
                    xmlDataSource.XPath = @"/CallCenters/CallCenter";
                    xmlDataSource.EnableCaching = false;
                    xmlDataSource.Data = GetCMS(WebStartDate.Text, WebEndDate.Text);
                    WHDG.DataSource = xmlDataSource;
                    WHDG.DataBind();
                }
            }
        }

        public void btnExport_Click(object sender, EventArgs e)
        {
            this.WebExcelExporter1.WorkbookFormat = Infragistics.Documents.Excel.WorkbookFormat.Excel97To2003;
            this.WebExcelExporter1.Export(this.WHDG);
        }

        public void Search(Object sender, EventArgs e)
        {
            using (XmlDataSource xmlDataSource = new XmlDataSource())
            {
                xmlDataSource.XPath = @"/CallCenters/CallCenter";
                xmlDataSource.EnableCaching = false;
                xmlDataSource.Data = GetCMS(WebStartDate.Text, WebEndDate.Text);
                WHDG.GridView.ClearDataSource();
                WHDG.DataSource = xmlDataSource;
                WHDG.DataBind();
            }
        }


        private string GetCMS(string WebStartDate, string WebEndDate)
        {
            string strSQL = "dbo.dashboard_callcenter_metrix4";
            string result = "";
            using (SqlConnection connection = new SqlConnection("Server = 10.50.8.80;User ID = jpmc;Password = cstsqa;DATABASE = cstsdb"))
            {
                using (SqlCommand command = new SqlCommand(strSQL, connection))
                {
                    command.CommandTimeout = 0;
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@startDate", WebStartDate);
                    command.Parameters.AddWithValue("@endDate", WebEndDate);

                    using (DataTable dataTable = new DataTable())
                    {
                        using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
                        {
                            dataAdapter.Fill(dataTable);
                        }

                        if (dataTable.Rows.Count > 0)
                        {
                            DataRow dataRow;
                            for (int i = 0; i < dataTable.Rows.Count; i++)
                            {
                                dataRow = dataTable.Rows[i];
                                result += dataRow[0].ToString();
                            }
                        }
                    }
                }
            }
            return result;
        }
    }