Solved

Export from Gridview to  Excel is only showing Headers

Posted on 2011-03-16
2
1,333 Views
Last Modified: 2012-08-13
I've been looking over this for a while today, I cannot figure out why the Excel Export is only exporting the headers. I have this same code on another page that is working perfectly. I cannot see what the difference might be.

 
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services.Protocols;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class LA_TaxResults : System.Web.UI.Page
{
    public class GridViewExportUtil
    {
        
        public static void Export(string fileName, GridView GridViewTax)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.AddHeader(
                "content-disposition", string.Format("attachment; filename={0}", fileName));
            HttpContext.Current.Response.ContentType = "application/ms-excel";

            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter htw = new HtmlTextWriter(sw))
                {
                    //  Create a form to contain the grid
                    Table table = new Table();
                    table.GridLines = GridViewTax.GridLines;

                    //  add the header row to the table
                    if (GridViewTax.HeaderRow != null)
                    {
                        GridViewExportUtil.PrepareControlForExport(GridViewTax.HeaderRow);
                        table.Rows.Add(GridViewTax.HeaderRow);
                    }

                    //  add each of the data rows to the table
                    foreach (GridViewRow row in GridViewTax.Rows)
                    {
                        GridViewExportUtil.PrepareControlForExport(row);
                        table.Rows.Add(row);
                    }

                    //  add the footer row to the table
                    if (GridViewTax.FooterRow != null)
                    {
                        GridViewExportUtil.PrepareControlForExport(GridViewTax.FooterRow);
                        table.Rows.Add(GridViewTax.FooterRow);
                    }

                    //  render the table into the htmlwriter
                    table.RenderControl(htw);

                    //  render the htmlwriter into the response
                    HttpContext.Current.Response.Write(sw.ToString());
                    HttpContext.Current.Response.End();
                }
            }
        }

        
        /// <summary>
        /// Replace any of the contained controls with literals
        /// </summary>
        /// <param name="control"></param>
        private static void PrepareControlForExport(Control control)
        {
            for (int i = 0; i < control.Controls.Count; i++)
            {
                Control current = control.Controls[i];
                if (current is Button)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as Button).Text));
                }
                if (current is LinkButton)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as LinkButton).Text));
                }
                else if (current is ImageButton)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as ImageButton).AlternateText));
                }
                else if (current is HyperLink)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as HyperLink).Text));
                }
                else if (current is DropDownList)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as DropDownList).SelectedItem.Text));
                }
                else if (current is CheckBox)
                {
                    control.Controls.Remove(current);
                    control.Controls.AddAt(i, new LiteralControl((current as CheckBox).Checked ? "True" : "False"));
                }

                if (current.HasControls())
                {
                    GridViewExportUtil.PrepareControlForExport(current);
                }
            }
        }
    }
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.ServerVariables["http_user_agent"].IndexOf("Chrome", StringComparison.CurrentCultureIgnoreCase) != -1)
            Page.ClientTarget = "uplevel";
        if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
            Page.ClientTarget = "uplevel";
    }  

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["ShowAgreement"] = null;
            ViewState["ShowID"] = null;
            ViewState["ShowAll"] = null;            
            if (ViewState["ShowAgreement"] != null || ViewState["ShowID"] != null || ViewState["ShowAll"] != null)
            {
                bool ShowAll = (bool)ViewState["ShowAll"];
                bool ShowID = (bool)ViewState["ShowID"];
                bool ShowAgreement = (bool)ViewState["ShowAgreement"];
                if (!ShowAll & !ShowID)
                {
                    this.GetSearchAgmntData();
                }
                if (!ShowAll & !ShowAgreement )
                {
                    this.GetSearchIDNo();
                }
                if (!ShowID & !ShowAgreement)
                {
                    this.GetMainData();
                }
            }
        }
    }


    private string GetConnectionString()
    {
        return
        System.Configuration.ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString;
    }

    protected void GetMainData()
    {
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString);
        string strTax = "SELECT ID, Rank_Main, Mapper_Main, State_Main, County_Main, GIS_Ref, Agmnt_No, Tract_Nos, Control_Stmnt, Problem, Resolution, Tax_ID, Date_Ini, Date_Resolved, Date_update, GIS_Comments FROM TaxProblems";
        SqlCommand cmdMain = new SqlCommand(strTax, conn);
        SqlDataAdapter adpMain = new SqlDataAdapter(cmdMain);
        DataTable dtMain = new DataTable("TaxProblems");
        adpMain.Fill(dtMain);
        GridViewTax.DataSource = dtMain;
        GridViewTax.DataBind();
        GridViewTax.GridLines = GridLines.Vertical;
    }


    protected void ShowResults_Click(object sender, EventArgs e)
    {
        ViewState["ShowAgreement"] = false;
        ViewState["ShowID"] = false;
        ViewState["ShowAll"] = true;
        GetMainData();
    }

    protected void Edit_GridView(object source, System.Web.UI.WebControls.GridViewEditEventArgs e)
    {
        // We use CommandEventArgs e to get the row which is being clicked
        // This also changes the DataGrid labels into Textboxes so user can edit them         
        GridViewTax.EditIndex = e.NewEditIndex;
        if (ViewState["ShowAgreement"] != null || ViewState["ShowID"] != null || ViewState["ShowAll"] != null)
        {
            bool ShowAll = (bool)ViewState["ShowAll"];
            bool ShowID = (bool)ViewState["ShowID"];
            bool ShowAgreement = (bool)ViewState["ShowAgreement"];
            if (!ShowAll & !ShowID)
            {
                this.GetSearchAgmntData();
            }
            if (!ShowAll & !ShowAgreement)
            {
                this.GetSearchIDNo();
            }
            if (!ShowID & !ShowAgreement)
            {
                this.GetMainData();
            }
        }
        GridViewTax.Visible = true;
        // Always bind the data so the datagrid can be displayed.
    }

    protected void Cancel_GridViewEdit(object sender, GridViewCancelEditEventArgs e)
    {

        //Reset the edit index.
        GridViewTax.EditIndex = -1;
        if (ViewState["ShowAgreement"] != null || ViewState["ShowID"] != null || ViewState["ShowAll"] != null)
        {
            bool ShowAll = (bool)ViewState["ShowAll"];
            bool ShowID = (bool)ViewState["ShowID"];
            bool ShowAgreement = (bool)ViewState["ShowAgreement"];
            if (!ShowAll & !ShowID)
            {
                this.GetSearchAgmntData();
            }
            if (!ShowAll & !ShowAgreement)
            {
                this.GetSearchIDNo();
            }
            if (!ShowID & !ShowAgreement)
            {
                this.GetMainData();
            }
        }
   }

    protected void GetSearchIDNo()
    {
        ContentPlaceHolder TaxSubmit = this.Master.FindControl("MainContent") as ContentPlaceHolder;
        TextBox IDSearchTxtBox = TaxSubmit.FindControl("IDSrchTB") as TextBox;
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString);
        string strID = "SELECT ID, Rank_Main, Mapper_Main, State_Main, County_Main, GIS_Ref, Agmnt_No, Tract_Nos, Control_Stmnt, Problem, Resolution, Tax_ID, Date_Ini, Date_Resolved, Date_update, GIS_Comments FROM TaxProblems  WHERE ID LIKE '%' + @ID + '%'";
        SqlCommand cmdID = new SqlCommand(strID, conn);
        SqlParameter IDNoSrch = new SqlParameter();
        IDNoSrch.ParameterName = "@ID";
        IDNoSrch.Value = IDSearchTxtBox.Text;
        cmdID.Parameters.Add(IDNoSrch);
        SqlDataAdapter adpMain = new SqlDataAdapter(cmdID);
        DataTable dtIDSrch = new DataTable("QC_IDSearch");
        adpMain.Fill(dtIDSrch);
        GridViewTax.DataSource = dtIDSrch;
        GridViewTax.DataBind();
        GridViewTax.GridLines = GridLines.Vertical;
    }

    protected void GetSearchAgmntData()
    {
        ContentPlaceHolder LASubmit = this.Master.FindControl("MainContent") as ContentPlaceHolder;
        TextBox AgmntSearchTxtBox = LASubmit.FindControl("AgmntSrchTB") as TextBox;
        SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString);
        string strAgmnt = "SELECT ID, Rank_Main, Mapper_Main, State_Main, County_Main, GIS_Ref, Agmnt_No, Tract_Nos, Control_Stmnt, Problem, Resolution, Tax_ID, Date_Ini, Date_Resolved, Date_update, GIS_Comments FROM TaxProblems  WHERE Agmnt_No LIKE '%' + @AgmntNumber + '%'";
        SqlCommand cmdMain = new SqlCommand(strAgmnt, conn);
        SqlParameter AgmntNoSrch = new SqlParameter();
        AgmntNoSrch.ParameterName = "@AgmntNumber";
        AgmntNoSrch.Value = AgmntSearchTxtBox.Text;
        cmdMain.Parameters.Add(AgmntNoSrch);
        SqlDataAdapter adpMain = new SqlDataAdapter(cmdMain);
        DataTable dtAgreement = new DataTable("QC_AgmntSearch");
        adpMain.Fill(dtAgreement);
        GridViewTax.DataSource = dtAgreement;
        GridViewTax.DataBind();
        GridViewTax.GridLines = GridLines.Vertical;
    }

    protected void GridViewTax_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString);
        string delStatement = "DELETE FROM TaxProblems WHERE ID = @ID";
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(delStatement, conn);
            SqlParameter IDMainNo = new SqlParameter();
            IDMainNo.ParameterName = "@ID";
            IDMainNo.Value = GridViewTax.DataKeys[e.RowIndex].Value;
            cmd.Parameters.Add(IDMainNo);
            cmd.ExecuteNonQuery();
            if (ViewState["ShowAgreement"] != null || ViewState["ShowID"] != null || ViewState["ShowAll"] != null)
            {
                bool ShowAll = (bool)ViewState["ShowAll"];
                bool ShowID = (bool)ViewState["ShowID"];
                bool ShowAgreement = (bool)ViewState["ShowAgreement"];
                if (!ShowAll & !ShowID)
                {
                    this.GetSearchAgmntData();
                }
                if (!ShowAll & !ShowAgreement)
                {
                    this.GetSearchIDNo();
                }
                if (!ShowID & !ShowAgreement)
                {
                    this.GetMainData();
                }
            }

         }

        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Deletion Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }

        finally
        {

            conn.Close();

        }
    }

    protected void gvMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        GridViewRow row = GridViewTax.Rows[e.RowIndex];
        ContentPlaceHolder LASubmit = this.Master.FindControl("MainContent") as ContentPlaceHolder;
        TextBox ResolutionUpdateTB = row.FindControl("TextBoxResolution") as TextBox;
        TextBox DateResUpdateTB = row.FindControl("TextBoxDateResolved") as TextBox;
        TextBox DateUpdatedTxtBox = row.FindControl("TextBoxDateGisUpdate") as TextBox;
        TextBox GISMapperCmntTB = row.FindControl("TextBoxGisComments") as TextBox;
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LA_DBASEConnectionString"].ConnectionString);
        SqlCommand cmdUpdate = new SqlCommand("UPDATE [TaxProblems] SET [Date_update] = @Date_update, [GIS_Comments] = @GIS_Comments, [Resolution] = @Resolution, [Date_Resolved] = @Date_Resolved  WHERE [ID] = @ID", conn);
        int intResult = 0;
        SqlParameter IDMainNo = new SqlParameter();
        IDMainNo.ParameterName = "@ID";
        IDMainNo.Value = GridViewTax.DataKeys[e.RowIndex].Value;
        cmdUpdate.Parameters.Add(IDMainNo);
        cmdUpdate.Parameters.Add("@Resolution", SqlDbType.NVarChar);
        cmdUpdate.Parameters["@Resolution"].Value = ResolutionUpdateTB.Text;
        cmdUpdate.Parameters.Add("@GIS_Comments", SqlDbType.NVarChar);
        cmdUpdate.Parameters["@GIS_Comments"].Value = GISMapperCmntTB.Text;
        cmdUpdate.Parameters.Add("@Date_Resolved", SqlDbType.DateTime);
        cmdUpdate.Parameters["@Date_Resolved"].Value = DateResUpdateTB.Text;
        cmdUpdate.Parameters.Add("@Date_update", SqlDbType.DateTime);
        cmdUpdate.Parameters["@Date_update"].Value = DateUpdatedTxtBox.Text;       

        try
        {
            conn.Open();
            intResult = Convert.ToInt32(cmdUpdate.ExecuteNonQuery());
            if (intResult != 0)
            {

                Label MsgLabel = LASubmit.FindControl("MessageLabel") as Label;
                MsgLabel.Text = "Record Updated.";
                GridViewTax.EditIndex = -1;
                if (ViewState["ShowAgreement"] != null || ViewState["ShowID"] != null || ViewState["ShowAll"] != null)
                {
                    bool ShowAll = (bool)ViewState["ShowAll"];
                    bool ShowID = (bool)ViewState["ShowID"];
                    bool ShowAgreement = (bool)ViewState["ShowAgreement"];
                    if (!ShowAll & !ShowID)
                    {
                        this.GetSearchAgmntData();
                    }
                    if (!ShowAll & !ShowAgreement)
                    {
                        this.GetSearchIDNo();
                    }
                    if (!ShowID & !ShowAgreement)
                    {
                        this.GetMainData();
                    }
                }
            }
            else
            {
                Label MsgLabel = LASubmit.FindControl("MessageLabel") as Label;
                MsgLabel.Text = "No Records Updated";
            }
        }
        catch (SqlException ex)
        {
            Label MsgLabel = LASubmit.FindControl("MessageLabel") as Label;
            MsgLabel.Text = ex.Message;
        }
        finally
        {
            conn.Close();
        }
    }
    protected void SearchBttn_Click(object sender, EventArgs e)
    {
        ContentPlaceHolder LASubmit = this.Master.FindControl("MainContent") as ContentPlaceHolder;
        
        TextBox IDNoSearchTxtBox = LASubmit.FindControl("IDSrchTB") as TextBox;
        if (IDNoSearchTxtBox.Text.Length > 0)
        {
            ViewState["ShowAgreement"] = false;
            ViewState["ShowID"] = true;
            ViewState["ShowAll"] = false;
            GetSearchIDNo();
            GridViewTax.Visible = true;
        }

        TextBox AgreementSearchTextBox = LASubmit.FindControl("AgmntSrchTB") as TextBox;
        if (AgreementSearchTextBox.Text.Length > 0)
        {
            ViewState["ShowAgreement"] = true;
            ViewState["ShowID"] = false;
            ViewState["ShowAll"] = false;
            GetSearchAgmntData();
            GridViewTax.Visible = true;
        }
    }
    protected void ExcelExport_Click(object sender, EventArgs e)
    {
        ContentPlaceHolder LAResults = this.Master.FindControl("MainContent") as ContentPlaceHolder;
        RadioButtonList ExportChoices = LAResults.FindControl("ExportOptions") as RadioButtonList;
          if (ExportChoices.SelectedIndex == 0)
        {
            GridViewTax.AllowPaging = true;
            GridViewTax.DataBind();
            GridViewExportUtil.Export("TaxDbaseExport.xls", GridViewTax);
        }

        if (ExportChoices.SelectedIndex == 2)
        {
            //  the user wants all rows exported, turn off paging
            //  and rebing the grid before sending it to the export
            //  utility
            GridViewTax.AllowPaging = false;
            GridViewTax.DataBind();
            GridViewExportUtil.Export("TaxDbaseExport.xls", GridViewTax);
        }
        if (ExportChoices.SelectedIndex == 1)
        {
            //  the user wants just the first 100,
            //  adjust the PageSize and rebind
            GridViewTax.PageSize = 100;
            GridViewTax.DataBind();
            GridViewExportUtil.Export("TaxDbaseExport.xls", GridViewTax);
        }

    }
}

Open in new window


 
<%@ Page Title="" Language="C#" MasterPageFile="Site.master" AutoEventWireup="true"
    CodeFile="Copy of LA_TaxResults.aspx.cs" MaintainScrollPositionOnPostback="true" Inherits="LA_TaxResults" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <title>Tax Problems Database Results</title>
    <style type="text/css">
        .page
        {
            width: 3000px;
            background-color: #fff;
            margin: 20px auto 0px auto;
            border: 1px solid #496077;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <br />
    <script type="text/javascript" src="scripts/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.blockUI.js"></script>
    <script type="text/javascript">
        function BlockUI(elementID) {
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_beginRequest(function () {
                $("#" + elementID).block({ message: '<table align = "center"><tr><td>' +
     '<img src="images/loadingAnim.gif"/></td></tr></table>',
                    css: {},
                    overlayCSS: { backgroundColor: '#000000', opacity: 0.6, border: '3px solid #63B2EB'
                    }
                });
            });

            prm.add_endRequest(function () {
                $("#" + elementID).unblock();
            });
        }
        $(document).ready(function () {

            BlockUI("dvGrid");

            $.blockUI.defaults.css = {};

        });

    </script>
    <br />
    <br />
    <h2>
        Tax Database Results Table</h2>
    <br />
    <br />
    <table>
        <tr>
            <td>
                <asp:Button ID="ExcelExport" runat="server" Text="Export to EXCEL" OnClick="ExcelExport_Click" />
            </td>
            <td>
                <asp:RadioButtonList runat="server" ID="ExportOptions" RepeatDirection="Horizontal">
                    <asp:ListItem Value="1">Current Page</asp:ListItem>
                    <asp:ListItem Value="2">Top 100 Records</asp:ListItem>
                    <asp:ListItem Value="3">Export All Records</asp:ListItem>
                </asp:RadioButtonList>
            </td>
    </table>
    <br />
    <br />
    <asp:UpdatePanel ID="UpdatePanelTaxResults" runat="server">
        <ContentTemplate>
            <table>
                <tr>
                    <td>
                        ID Number:
                    </td>
                    <td>
                        <asp:TextBox ID="IDSrchTB" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;
                    </td>
                    <td>
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td>
                        Agreement No:&nbsp;&nbsp;
                    </td>
                    <td>
                        <asp:TextBox ID="AgmntSrchTB" runat="server"></asp:TextBox>
                    </td>
                </tr>
            </table>
            <br />
            <br />
            <table>
                <tr>
                    <td>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Button ID="SearchBttn" runat="server" Text="Search"
                            OnClick="SearchBttn_Click" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                    <td>
                        <asp:Button ID="ShowAllResults" runat="server" Text="Show All Records" OnClick="ShowResults_Click" />
                    </td>
                </tr>
            </table>
            <br />
            <br />
            <br />
            <br />
            <asp:Label ID="MessageLabel" runat="server" Text=""></asp:Label>
            <br />
            <br />
            <div id="dvGrid">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:GridView ID="GridViewTax" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
                            EmptyDataText="There are no data records to display." AllowPaging="False" AllowSorting="True"
                            EnableModelValidation="True" CellPadding="4" ForeColor="#333333" GridLines="None"
                            OnRowCancelingEdit="Cancel_GridViewEdit" OnRowDeleting="GridViewTax_RowDeleting"
                            OnRowEditing="Edit_GridView" OnRowUpdating="gvMain_RowUpdating">
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                            <Columns>
                                <asp:TemplateField HeaderText="ID" SortExpression="ID">
                                    <ItemTemplate>
                                        <asp:Label ID="LabelID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Rank&nbsp;(Importance)" SortExpression="Rank_Main">
                                    <ItemTemplate>
                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Rank_Main") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Mapper" SortExpression="Mapper_Main">
                                    <ItemTemplate>
                                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Mapper_Main") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="State" SortExpression="State_Main">
                                    <ItemTemplate>
                                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("State_Main") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="County" SortExpression="County_Main">
                                    <ItemTemplate>
                                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("County_Main") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="GISREF" SortExpression="GIS_Ref">
                                    <ItemTemplate>
                                        <asp:Label ID="Label6" Width="45" runat="server" Text='<%# Bind("GIS_Ref") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Agreement&nbsp;Number" SortExpression="Agmnt_No">
                                    <ItemTemplate>
                                        <asp:Label ID="Label7" Width="50" runat="server" Text='<%# Bind("Agmnt_No") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tract&nbsp;Numbers" SortExpression="Tract_Nos">
                                    <ItemTemplate>
                                        <asp:Label ID="Label8" runat="server" Text='<%# Bind("Tract_Nos") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Control&nbsp;Statment" SortExpression="Control_Stmnt">
                                    <ItemTemplate>
                                        <asp:Label ID="Label9" runat="server" Text='<%# Bind("Control_Stmnt") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Tax&nbsp;ID" SortExpression="Tax_ID">
                                    <ItemTemplate>
                                        <asp:Label ID="Label12" runat="server" Text='<%# Bind("Tax_ID") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBox11" runat="server" Text='<%# Bind("Tax_ID") %>'></asp:TextBox>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Problem" SortExpression="Problem">
                                    <ItemTemplate>
                                        <asp:Label ID="Label10" Width="250" runat="server" Text='<%# Bind("Problem") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Resolution" SortExpression="Resolution">
                                    <ItemTemplate>
                                        <asp:Label ID="Label11" runat="server" Width="250" Text='<%# Bind("Resolution") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBoxResolution" runat="server" Text='<%# Bind("Resolution") %>'
                                            Height="250px" Width="550px" TextMode="MultiLine"></asp:TextBox>
                                        <br />
                                        <br />
                                        <asp:RegularExpressionValidator ID="RegExpValRes" runat="server" ControlToValidate="TextBoxResolution"
                                            ValidationExpression="^[\s\S]{0,2000}$" Display="Dynamic" ErrorMessage="Resolution Box has a Limit of 2000 Characters"
                                            EnableClientScript="true">
                                        </asp:RegularExpressionValidator>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Date&nbsp;Problem&nbsp;Initiated" SortExpression="Date_Ini">
                                    <ItemTemplate>
                                        <asp:Label ID="Label13" runat="server" Text='<%# Bind("Date_Ini", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Date&nbsp;Resolved" SortExpression="Date_Resolved">
                                    <ItemTemplate>
                                        <asp:Label ID="Label14" runat="server" Text='<%# Bind("Date_Resolved", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBoxDateResolved" runat="server" Text='<%# Eval("Date_Resolved", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                                        <asp:CompareValidator ID="CompareDateResolved" runat="server" ControlToValidate="TextBoxDateResolved"
                                            Operator="DataTypeCheck" Type="Date" ErrorMessage="Invalid Date Or Format: Use (MM/DD/YYYY)" />
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Date&nbsp;Problem&nbsp;Updated" SortExpression="Date_update">
                                    <ItemTemplate>
                                        <asp:Label ID="Label15" runat="server" Text='<%# Bind("Date_update", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBoxDateGisUpdate" runat="server" Text='<%# Eval("Date_update", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
                                        <asp:CompareValidator ID="CompareDateUpdated" runat="server" ControlToValidate="TextBoxDateGisUpdate"
                                            Operator="DataTypeCheck" Type="Date" ErrorMessage="Invalid Date Or Format: Use (MM/DD/YYYY)" />
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="GIS&nbsp;Comments" SortExpression="GIS_Comments">
                                    <ItemTemplate>
                                        <asp:Label ID="Label16" runat="server" Text='<%# Bind("GIS_Comments") %>'></asp:Label>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:TextBox ID="TextBoxGisComments" runat="server" Text='<%# Bind("GIS_Comments") %>'
                                            Height="250px" Width="550px" TextMode="MultiLine"></asp:TextBox>
                                        <br />
                                        <br />
                                        <asp:RegularExpressionValidator ID="RegExpValGisComment" runat="server" ControlToValidate="TextBoxGisComments"
                                            ValidationExpression="^[\s\S]{0,2000}$" Display="Dynamic" ErrorMessage="Resolution Box has a Limit of 2000 Characters"
                                            EnableClientScript="true">
                                        </asp:RegularExpressionValidator>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField ShowHeader="False">
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                            Text="Edit"></asp:LinkButton>
                                        <br />
                                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                                            Text="Delete"></asp:LinkButton>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                            Text="Update"></asp:LinkButton>
                                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Cancel"></asp:LinkButton>
                                    </EditItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <EditRowStyle BackColor="#999999" />
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        </asp:GridView>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="GridViewTax" />
                    </Triggers>
                </asp:UpdatePanel>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

Open in new window

0
Comment
Question by:GravitaZ24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 400 total points
ID: 35151979
Hi,

Are you sure that when you are calling the Export Method the GridView have Records? Because according to your code, if the users clicks the Export Button it will no call the GetMainData(), so the Gridview will be emtpy.

In your ExcelExport_Click event add

this.GetMainData();

Before this

            GridViewTax.DataBind();
            GridViewExportUtil.Export("TaxDbaseExport.xls", GridViewTax);
0
 

Author Closing Comment

by:GravitaZ24
ID: 35152208
Oh wow, Thank you! I can't believe I missed that. The other application I had the Gridview populated on the ASP.NET page. That is why I missed it. Thanks Again!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question