Questo è il codebehind

codice:
namespace CRM
{
    public partial class GestioneDilazioniProvvigioni : System.Web.UI.Page
    {
        private SqlConnection sqlConnection;
        private MsnHelper msnHelper;
        private Int32 IDOwner;
        private DataSet dataSet;
        decimal TotaleImponibile;
        decimal TotaleTotale;
        decimal TotaleProvvigione;
        decimal TotaleIncassato;

        protected void Page_Load(object sender, EventArgs e) 
        {                 
            msnHelper = MsnHelper.MsnHelperFactory();	
            OpenSqlConnection();

            if (!this.Page.IsPostBack)
            {                
                IDOwner = SessionWrapper.UsersID;
                CarcicaDDL();

            }

           if (gwElenco.Rows.Count == 0)
           {
               btnEsporta.Visible = false;
               btnSalva.Visible = false;
           }
        }


        protected void btnRicerca_Click(object sender, EventArgs e)
        {
            BindGrid();
        }



        private void BindGrid()
        {
            string Owner_Filter = ddlRicercaOwner.SelectedValue;
            string Tipo_Filter = null;
            string DataInizio_Filter;
            string DataFine_Filter;

            if ((Owner_Filter == "") || (Owner_Filter == "Tutti..."))
                Owner_Filter = null;

            if ((tbRicercaDataInizio.Text != "") && (tbRicercaDataFine.Text != ""))
            {
                DateTime DataInizio = Convert.ToDateTime(tbRicercaDataInizio.Text);
                DateTime DataFine = Convert.ToDateTime(tbRicercaDataFine.Text);
                DataInizio_Filter = msnHelper.DataHelper.ConvertDate(DataInizio);
                DataFine_Filter = msnHelper.DataHelper.ConvertDateNextDay(DataFine);
            }
            else
            {
                DataInizio_Filter = null;
                DataFine_Filter = null;
            }


            if (ddlRicercaContratto.SelectedValue == "")
                Tipo_Filter = null;
            else
                Tipo_Filter = ddlRicercaContratto.SelectedValue;


            DataSet dsElenco;

            
                dsElenco = msnHelper.DataHelper.GetDilazioniProvvigioni(sqlConnection,
                                                                                     Owner_Filter,
                                                                                     Tipo_Filter,
                                                                                     DataInizio_Filter,
                                                                                     DataFine_Filter);
   

            if (dsElenco.Tables[0].Rows.Count >= 0)
            {
                gwElenco.DataSource = dsElenco.Tables[0];
                gwElenco.DataBind();

                gvExcel.DataSource = dsElenco.Tables[0];
                gvExcel.DataBind();
            }
        

           if (gwElenco.Rows.Count > 0)
           {
               btnEsporta.Visible = true;
               btnSalva.Visible = true;
           }
           else
           {
               btnEsporta.Visible = false;
               btnSalva.Visible = false;
           }
        }

 
        protected void gwElenco_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.RowType == DataControlRowType.DataRow)
            //{
            // .... questo l'ho commentato tutto, quindi non lo posto


        }


        protected void btnSalva_Click(object sender, EventArgs e)
        {
            

            //Aggiornameno GridView
            BindGrid();
        }

  

       protected void CarcicaDDL()
        {
            //DDL Ricerca Owner
            msnHelper.PresentationHelper.FillWithOwner(ddlRicercaOwner.Items, IDOwner, sqlConnection);       
            //Viene verificato se l'utente ha la possibilità di visualizzare i dati di TUTTI gli altri utenti
            if(SessionWrapper.VisualizzaTutti == true)           
                ddlRicercaOwner.Items.Insert(0, new ListItem("Tutti...", ""));
        }



        protected void btnAnagrafica_Click(object sender, EventArgs e)
        {
 
        }

  
      protected void btnConferma_Click(object sender, EventArgs e)
        {
            String IDAnagraficaContrattiDilazione = ((Button)(sender)).Attributes["IDAnagraficaContrattiDilazione"].ToString();
            
            //Viene segnata come validata la dilazione in oggetto
            msnHelper.DataHelper.UpdateDilazioneValidaProvvigione(sqlConnection, IDAnagraficaContrattiDilazione);

            BindGrid();
        }

        protected decimal GetValoreImponibile(decimal Price)
        {
            TotaleImponibile += Price;
            return Price;
        }

        protected decimal GetValoreImponibileTotale()
        {
            return TotaleImponibile;
        }

        protected decimal GetValoreTotale(decimal Price)
        {
            TotaleTotale += Price;
            return Price;
        }

        protected decimal GetValoreTotaleTotale()
        {
            return TotaleTotale;
        }

        protected decimal GetValoreIncassato(decimal Price)
        {
            TotaleIncassato += Price;
            return Price;
        }

        protected decimal GetValoreIncassatoTotale()
        {
            return TotaleIncassato;
        }


        protected decimal GetValoreProvvigione(decimal Price)
        {
            TotaleProvvigione += Price;
            return Price;
        }

        protected decimal GetValoreProvvigioneTotale()
        {
            return TotaleProvvigione;
        }

        #region Gestione ordinamento della griglia

        private string GridViewSortDirection
        {
            get { return ViewState["SortDirection"] as string ?? "ASC"; }
            set { ViewState["SortDirection"] = value; }
        }

        private string GridViewSortExpression
        {
            get { return ViewState["SortExpression"] as string ?? string.Empty; }
            set { ViewState["SortExpression"] = value; }
        }

        private string GetSortDirection()
        {
            switch (GridViewSortDirection)
            {
                case "ASC":
                    GridViewSortDirection = "DESC";
                    break;

                case "DESC":
                    GridViewSortDirection = "ASC";
                    break;
            }
            return GridViewSortDirection;
        }

        protected void gwElenco_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gwElenco.DataSource = SortDataTable(gwElenco.DataSource as DataTable, true);
            gwElenco.PageIndex = e.NewPageIndex;
            //BindGrid();
            gwElenco.DataBind();
        }

        protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
        {
            if (dataTable != null)
            {
                DataView dataView = new DataView(dataTable);
                if (GridViewSortExpression != string.Empty)
                {
                    if (isPageIndexChanging)
                    {
                        dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
                    }
                    else
                    {
                        dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
                    }
                }
                return dataView;
            }
            else
            {
                return new DataView();
            }
        }

        protected void gwElenco_Sorting(object sender, GridViewSortEventArgs e)
        {
            BindGrid();
            GridViewSortExpression = e.SortExpression;
            int pageIndex = gwElenco.PageIndex;
            gwElenco.DataSource = SortDataTable(gwElenco.DataSource as DataTable, false);
            gwElenco.DataBind();
            gwElenco.PageIndex = pageIndex;
        }

        #endregion

        #region Metodi della pagina

        protected void Page_Unload(object sender, EventArgs e)
        {
            CloseSqlConnection();
        }

        private void OpenSqlConnection()
        {
            sqlConnection = msnHelper.DataHelper.CreateSqlConnection();
            sqlConnection.Open();
        }

        private void CloseSqlConnection()
        {
            if (sqlConnection != null)
                sqlConnection.Close();
        }

        #endregion

        protected void btnEsporta_Click(object sender, EventArgs e)
        {
            //  pass the grid that for exporting ...
            GridViewExportUtil.Export("Customers.xls", this.gvExcel);

        }

     }
}