/// <summary>
		/// If the datagrid was not sorted and bound via the "_Sort" method it will be bound at this time using
		/// default values
		/// </summary>
		/// <param name="e"></param>
		protected override void OnPreRender (EventArgs e)
		{
			base.OnPreRender (e);
			
			// Only bind if not a user selected sort
			if (!IsReadComplete)
			{
				LoadData ();

				// Use DocumentComparer to do sort based on the default sort order (mobjSettings.SortOrder)
				var docComparer = new DocumentComparer (DocumentsSettings.GetSortColumnList (this.LocalResourceFile));
				mobjDocumentList.Sort (docComparer.Compare);

				//Bind the grid
				grdDocuments.DataSource = mobjDocumentList;
				grdDocuments.DataBind ();
			}

			// Localize the Data Grid
			// REVIEW: Original: Localization.LocalizeDataGrid(ref grdDocuments, this.LocalResourceFile);
            Localization.LocalizeGridView (ref grdDocuments, this.LocalResourceFile);
		}
		private void LoadData ()
		{
			string strCacheKey = null;
			
			if (IsReadComplete)
				return;

			// Only read from the cache if the users is not logged in
			strCacheKey = this.DataCacheKey + ";anon-doclist";
			if (!Request.IsAuthenticated)
			{
				mobjDocumentList = (List<DocumentInfo>)DataCache.GetCache (strCacheKey);
			}

			if (mobjDocumentList == null)
			{
				//	mobjDocumentList = (ArrayList) DocumentsController.GetObjects<DocumentInfo>(ModuleId); // PortalId!!!

				mobjDocumentList = DocumentsController.GetDocuments (ModuleId, PortalId).ToList ();

				// Check security on files
				DocumentInfo objDocument = null;

                for (var intCount = mobjDocumentList.Count - 1; intCount >= 0; intCount--)
				{
					objDocument = mobjDocumentList [intCount];
                    if (objDocument.Url.IndexOf ("fileid=", StringComparison.InvariantCultureIgnoreCase) >= 0)
					{
						// document is a file, check security
						var objFile = FileManager.Instance.GetFile (int.Parse (objDocument.Url.Split ('=') [1]));
					
						//if ((objFile != null) && !PortalSecurity.IsInRoles(FileSystemUtils.GetRoles(objFile.Folder, PortalSettings.PortalId, "READ"))) {
						if (objFile != null)
						{
							var folder = FolderManager.Instance.GetFolder (objFile.FolderId);
                            if (folder != null && !FolderPermissionController.CanViewFolder ((FolderInfo)folder))
							{
								// remove document from the list
                                mobjDocumentList.Remove (objDocument);
								continue;
							}
						}
					}
					
					// remove unpublished documents from the list
					if (!objDocument.IsPublished && !IsEditable)
					{
						mobjDocumentList.Remove (objDocument);
						continue;
					}

					objDocument.OnLocalize += new LocalizeHandler (OnLocalize);
				}

				// Only write to the cache if the user is not logged in
				if (!Request.IsAuthenticated)
				{
					DataCache.SetCache (strCacheKey, mobjDocumentList, new TimeSpan (0, 5, 0));
				}
			}

			//Sort documents
			var docComparer = new DocumentComparer (DocumentsSettings.GetSortColumnList (this.LocalResourceFile));
			mobjDocumentList.Sort (docComparer.Compare);

			IsReadComplete = true;
		}
		/// <summary>
		/// Process user-initiated sort operation
		/// </summary>
		/// <param name="source"></param>
		/// <param name="e"></param>
		/// <remarks></remarks>
		/// <history>
		/// 	[msellers]	5/17/2007	 Added
		/// </history>
        protected void grdDocuments_Sorting (object sender, GridViewSortEventArgs e)
		{
			ArrayList objCustomSortList = new ArrayList ();
			DocumentsSortColumnInfo objCustomSortColumn = new DocumentsSortColumnInfo ();
			DocumentsSortColumnInfo.SortDirection objCustomSortDirecton = DocumentsSortColumnInfo.SortDirection.Ascending;
			string strSortDirectionString = "ASC";

			// Set the sort column name
			objCustomSortColumn.ColumnName = e.SortExpression;

			// Determine if we need to reverse the sort.  This is needed if an existing sort on the same column existed that was desc
			if (ViewState ["CurrentSortOrder"] != null && ViewState ["CurrentSortOrder"].ToString () != string.Empty)
			{
				string existingSort = ViewState ["CurrentSortOrder"].ToString ();
				if (existingSort.StartsWith (e.SortExpression) && existingSort.EndsWith ("ASC"))
				{
					objCustomSortDirecton = DocumentsSortColumnInfo.SortDirection.Descending;
					strSortDirectionString = "DESC";
				}
			}

			// Set the sort
			objCustomSortColumn.Direction = objCustomSortDirecton;
			objCustomSortList.Add (objCustomSortColumn);

			var docComparer = new DocumentComparer (objCustomSortList);
			mobjDocumentList.Sort (docComparer.Compare);
			grdDocuments.DataSource = mobjDocumentList;
			grdDocuments.DataBind ();

			// Save the sort to viewstate
			ViewState ["CurrentSortOrder"] = e.SortExpression + " " + strSortDirectionString;

			// Mark as a user selected sort
			IsReadComplete = true;
		}