private void grdSearchResults_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
        {
            string attrFilterDef    = (string)ViewState["AttributesFilter"];
            string contextFilterDef = (string)ViewState["ContextFilter"];
            int    recStart         = grdSearchResults.CurrentPageIndex * grdSearchResults.PageSize;
            int    recNumber        = grdSearchResults.PageSize;
            string orderByAttribute = e.SortExpression;

            ViewState["OrderByAttribute"] = e.SortExpression;
            OrderByAttribute = e.SortExpression;

            DocLinkUrl_Begin = (string)ViewState["DocLinkUrl_Begin"];
            DocLinkUrl_End   = (string)ViewState["DocLinkUrl_End"];


            try
            {
                DocSearch search = new DocSearch();
                if (search.Find(attrFilterDef.ToString(), contextFilterDef, orderByAttribute, recStart, recNumber))
                {
                    //grdSearchResults.CurrentPageIndex = e.NewPageIndex;
                    grdSearchResults.DataSource       = search.ResultSet;
                    grdSearchResults.VirtualItemCount = search.VirtualCount;
                    grdSearchResults.DataBind();
                    grdSearchResults.Visible = true;
                }
                else
                {
                    grdSearchResults.Visible = false;
                }

                UpdateResultInfo(search);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }
        public void InitSearch()
        {
            try
            {
                ArrayList attrFilters = new ArrayList();

                attrFilters.Add(DocSearch.FilterDateRange("DateReceived", DateReceived_From, DateReceived_To));
                attrFilters.Add(DocSearch.FilterDateRange("DocumentDate", DocumentDate_From, DocumentDate_To));
                attrFilters.Add(DocSearch.FilterDateRange("CreationTime", CreationTime_From, CreationTime_To));

                attrFilters.Add(DocSearch.FilterStringEquals("Id", Id));
                attrFilters.Add(DocSearch.FilterString("IncomingNumber", IncomingNumber));
                attrFilters.Add(DocSearch.FilterString("OutgoingNumber", OutgoingNumber));
                attrFilters.Add(DocSearch.FilterString("Subject", Subject));
                attrFilters.Add(DocSearch.FilterString("Header", Header));
                attrFilters.Add(DocSearch.FilterString("D.FileName", FileName));
                attrFilters.Add(DocSearch.FilterString("ArchiveFileNames", ArchiveFileNames));

                attrFilters.Add(DocSearch.FilterEnumeration("DocTypeId", DocTypeId_Enum));
                attrFilters.Add(DocSearch.FilterEnumeration("DocSourceId", DocSourceId_Enum));
                attrFilters.Add(DocSearch.FilterEnumeration("DocCategoryId", DocCategoryId_Enum));

                if (IsRead != null && IsRead.Length > 0)
                {
                    attrFilters.Add(DocSearch.FilterIsRead(IsRead == "1"));
                }

                if (IsFavorite != null && IsFavorite.Length > 0)
                {
                    attrFilters.Add(DocSearch.FilterIsFavorite(IsFavorite == "1"));
                }


                StringBuilder attrFilterDef = new StringBuilder();
                foreach (string flt in attrFilters)
                {
                    if (flt == null || flt.Length == 0)
                    {
                        continue;
                    }
                    if (attrFilterDef.Length != 0)
                    {
                        attrFilterDef.Append(" AND ");
                    }
                    attrFilterDef.Append(flt);
                }

                //if(ContextQuery != null && ContextQuery.Trim().Length >0)
                //	ContextQuery = ContextQuery + " zmqpxnowcbievruytalskdjfhgxs";
                // well, this is the only solution filter  IDX IGNORED WORDS exception
                // unfortunately it's impossible to identify this error

                String contextFilterDef = DocSearch.FilterContext(ContextQuery);

                ViewState["AttributesFilter"] = attrFilterDef.ToString();
                ViewState["ContextFilter"]    = contextFilterDef.ToString();
                ViewState["OrderByAttribute"] = OrderByAttribute;


                ViewState["DocLinkUrl_Begin"] = DocLinkUrl_Begin;
                ViewState["DocLinkUrl_End"]   = DocLinkUrl_End;



                DocSearch search = new DocSearch();
                if (search.Find(attrFilterDef.ToString(), contextFilterDef, OrderByAttribute, 0, PageSize))
                {
                    grdSearchResults.DataSource = search.ResultSet;
                    grdSearchResults.PageSize   = PageSize;
                    //grdSearchResults.CurrentPageIndex = 0;
                    grdSearchResults.VirtualItemCount = search.VirtualCount;
                    grdSearchResults.DataBind();
                    grdSearchResults.Visible = true;
                }
                else
                {
                    grdSearchResults.Visible = false;
                }

                UpdateResultInfo(search);
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }