private void BindGridData(GridSortCommandEventArgs sortEventArgs)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["type"]) && Request.QueryString["type"] == "unpaid")
        {
            int pageSize = 20;
            int pageNumber = gridInvoiceUnpaid.CurrentPageIndex + 1;
            string sortExpress = string.Empty;
            string sortExpressInvert = string.Empty;
            foreach (GridSortExpression item in gridInvoiceUnpaid.MasterTableView.SortExpressions)
            {
                GridSortOrder newSortOrder = item.SortOrder;
                if (sortEventArgs != null && item.FieldName == sortEventArgs.SortExpression)
                {
                    newSortOrder = sortEventArgs.NewSortOrder;
                }

                if (!string.IsNullOrEmpty(sortExpress) && newSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (newSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += item.FieldName + " ASC";
                    sortExpressInvert += item.FieldName + " DESC";
                }
                else if (newSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += item.FieldName + " DESC";
                    sortExpressInvert += item.FieldName + " ASC";
                }
            }

            if (sortEventArgs != null && !sortExpress.Contains(sortEventArgs.SortExpression))
            {
                if (!string.IsNullOrEmpty(sortExpress) && sortEventArgs.NewSortOrder != GridSortOrder.None)
                {
                    sortExpress += ", ";
                    sortExpressInvert += ", ";
                }
                if (sortEventArgs.NewSortOrder == GridSortOrder.Ascending)
                {
                    sortExpress += sortEventArgs.SortExpression + " ASC";
                    sortExpressInvert += sortEventArgs.SortExpression + " DESC";
                }
                else if (sortEventArgs.NewSortOrder == GridSortOrder.Descending)
                {
                    sortExpress += sortEventArgs.SortExpression + " DESC";
                    sortExpressInvert += sortEventArgs.SortExpression + " ASC";
                }
            }

            if (string.IsNullOrEmpty(sortExpress))
            {
                sortExpress = "CompanyName ASC";
                sortExpressInvert = "CompanyName DESC";
            }

            InvoicesRepository repo = new InvoicesRepository();
            gridInvoiceUnpaid.VirtualItemCount = repo.CountUnpaidInvoices(pageSize, pageNumber, sortExpress, sortExpressInvert);
            IList<InvoiceUnpaid> list = repo.GetUnpaidInvoices(pageSize, pageNumber, sortExpress, sortExpressInvert);
            gridInvoiceUnpaid.DataSource = list;
        }
        else
        {
            gridInvoiceUnpaid.DataSource = new List<Invoices>();
        }
    }