Esempio n. 1
0
    public static void InitializeGridParameters(System.Web.UI.StateBag viewState, string formName, Type sortFields, int pageSize, int pageSizeLimit)
    {
        HttpRequest Request = HttpContext.Current.Request;
        string      Param;
        int         PageSize = pageSize;

        viewState[formName + "SortField"]  = Enum.Parse(sortFields, "Default");
        viewState[formName + "PageNumber"] = 1;
        Param = Request.QueryString[formName + "Order"];
        if (Param != null && Param.Length > 0)
        {
            try
            {
                viewState[formName + "SortField"] = Enum.Parse(sortFields, Param);
            }
            catch { }
        }
        Param = Request.QueryString[formName + "Dir"];
        if (Param == null || Param.Length == 0 || Param.ToLower() == "asc")
        {
            viewState[formName + "SortDir"] = SortDirections.Asc;
        }
        else
        {
            viewState[formName + "SortDir"] = SortDirections.Desc;
        }
        Param = Request.QueryString[formName + "Page"];
        int PageNumber;

        if (Param != null && Param.Length > 0)
        {
            try
            {
                PageNumber = Int32.Parse(Param);
                if (PageNumber >= 0)
                {
                    viewState[formName + "PageNumber"] = PageNumber;
                }
            }
            catch { }
        }
        Param = Request.QueryString[formName + "PageSize"];
        if (Param != null && Param.Length > 0)
        {
            try
            {
                PageSize = Int32.Parse(Param);
                if (PageSize <= 0)
                {
                    PageSize = pageSize;
                }
            }
            catch { }
        }
        if ((PageSize > pageSizeLimit || PageSize == 0) && pageSizeLimit != -1)
        {
            PageSize = pageSizeLimit;
        }
        viewState[formName + "PageSize"] = PageSize;
    }
		internal CssStyleCollection (StateBag bag) : this ()
		{
			this.bag = bag;
			if (bag != null && bag [AttributeCollection.StyleAttribute] != null)
				_value.Append (bag [AttributeCollection.StyleAttribute]);
			InitFromStyle ();
		}
Esempio n. 3
0
 public StateBag GetControlState(string controlUID)
 {
     StateBag retVal;
     if(! states.TryGetValue(controlUID, out retVal))
         states[controlUID] = retVal = new StateBag();
     return retVal;
 }
Esempio n. 4
0
 public static object GetPageViewStateProperty(Page p_page, StateBag p_ViewState, string p_sPropertyName, string p_sFormPropertyName, Type p_TargetType)
 {
     if (p_page.IsPostBack)
         return GetValue(p_page.Request.Form[p_sFormPropertyName], p_TargetType);
     else
         return GetValue(p_ViewState[p_sPropertyName], p_TargetType);
 }
        public static IWebSecurityAddIn Create(WebSecurityAddInData.WebSecurityAddInsRow addIn, StateBag viewStateContext, string languageCode)
        {
            IWebSecurityAddIn @in = null;
            try
            {
                if (addIn.TypeAssembly == null)
                {
                    throw new InvalidCastException();
                }
                @in = (IWebSecurityAddIn) Assembly.Load(addIn.TypeAssembly).CreateInstance(addIn.TypeNameSpace);
                @in.AddInDbId = addIn.WebSecurityAddInId;
                @in.Disabled = addIn.Disabled;
                string str = ResourceManager.GetString(addIn.Description);
                @in.Description = (str == null) ? addIn.Description : str;
                @in.SurveyId = addIn.SurveyID;
                @in.ViewState = viewStateContext;
                @in.Order = addIn.AddInOrder;
                @in.LanguageCode = languageCode;
///             return @in;
            }
            catch (NullReferenceException)
            {
                throw new InvalidCastException("specfied type " + addIn.TypeNameSpace + " could not be found in the specifed assembly " + addIn.TypeAssembly);
            }
            catch (InvalidCastException)
            {
                throw new InvalidCastException("specfied type " + addIn.TypeNameSpace + " must implement the IWebSecurityAddIn interface");
            }
            return @in;
        }
		public WebPartVerb (string clientHandler)
		{
			this.clientClickHandler = clientHandler;
			stateBag = new StateBag ();
			stateBag.Add ("clientClickHandler", clientHandler);

		}
        public static StateBag DeserializeStateBag(SerializationReader reader)
        {
            var flags = reader.ReadOptimizedBitVector32();
            var stateBag = new StateBag(flags[StateBagIsIgnoreCase]);

            if (flags[StateBagHasDirtyEntries])
            {
                var count = reader.ReadOptimizedInt32();

                for(var i = 0; i < count; i++)
                {
                    var key = reader.ReadOptimizedString();
                    var value = reader.ReadObject();

            // ReSharper disable PossibleNullReferenceException
                    stateBag.Add(key, value).IsDirty = true;
            // ReSharper restore PossibleNullReferenceException
                }
            }

            if (flags[StateBagHasCleanEntries])
            {
                var count = reader.ReadOptimizedInt32();

                for(var i = 0; i < count; i++)
                {
                    var key = reader.ReadOptimizedString();
                    var value = reader.ReadObject();

                    stateBag.Add(key, value);
                }
            }
            return stateBag;
        }
Esempio n. 8
0
 public static int getPreselectedJobsId(StateBag viewState)
 {
     string key = dict["PreselectedJobsId"].ToString();
     if(get(key, viewState) == null)
         set(key, -1, viewState);
     return (int)StateBagTask.get(key, viewState);
 }
Esempio n. 9
0
 public static ISearchJobDto getCurrentSearchJob(StateBag viewState)
 {
     string key = StateBagKey.SearchJob.ToString();
     if(get(key, viewState) == null)
         set(key, new SearchJobDto(), viewState);
     return get(key, viewState) as ISearchJobDto;
 }
Esempio n. 10
0
 private void Initialize(string method = "Default")
 {
     InitializeAllControls(testObject);
     _queryString = new NameValueCollection();
     if (method == MethodLoadGrid)
     {
         SetField(testObject, "txtstartDate", new TextBox
         {
             Text = "1/30/2018"
         });
         SetField(testObject, "txtendDate", new TextBox
         {
             Text = "3/30/2018"
         });
         _reportType = string.Empty;
         _viewState  = new StateBag();
         _viewState["tcSortField"]     = string.Empty;
         _viewState["tcSortDirection"] = string.Empty;
         _viewState["acSortField"]     = string.Empty;
         _viewState["acSortDirection"] = string.Empty;
         _viewState[TvSortFieldKey]    = string.Empty;
         _viewState[TvSortDirection]   = string.Empty;
         _viewState["_pageSize"]       = 1;
         _viewState["_currentIndex"]   = 1;
     }
     CreateShims(method);
 }
 protected override void LoadViewState(object savedState)
 {
     if (savedState != null)
     {
         Triplet triplet = (Triplet) savedState;
         base.LoadViewState(triplet.First);
         if (triplet.Second != null)
         {
             if (this._inputAttributesState == null)
             {
                 this._inputAttributesState = new StateBag();
                 this._inputAttributesState.TrackViewState();
             }
             this._inputAttributesState.LoadViewState(triplet.Second);
         }
         if (triplet.Third != null)
         {
             if (this._labelAttributesState == null)
             {
                 this._labelAttributesState = new StateBag();
                 this._labelAttributesState.TrackViewState();
             }
             this._labelAttributesState.LoadViewState(triplet.Second);
         }
     }
 }
Esempio n. 12
0
        internal static List<EstimadoDetDTO> CopiarPeriodos(DateTime fOrigenDesde, DateTime fOrigenHasta,
    DateTime fDestinoDesde, List<EstimadoDetDTO> lineas, StateBag viewState)
        {
            //Armo lista de elemtnos que SI reemplazo.
            //Busco en la coleccion, todas las lineas en el periodo, y con el aviso seleccionado.
            var lineasACopiar = lineas.FindAll(
                (x) =>
                    (x.Fecha >= fOrigenDesde
                    && x.Fecha <= fOrigenHasta));

            //Si encontre líneas a copiar...
            if (lineasACopiar.Count > 0)
            {
                EstimadoDetDTO nuevaLinea;
                DateTime fechaTmp;
                List<EstimadoDetDTO> lineasTmp = new List<EstimadoDetDTO>();
                TimeSpan diasEnElFuturo = fDestinoDesde.Subtract(fOrigenDesde);

                //Por cada linea que encontre, genero una nueva e igual, x dias en el futuro.
                foreach (var linea in lineasACopiar)
                {
                    nuevaLinea           = new EstimadoDetDTO();
                    nuevaLinea.RecId     = NextTempRecId(viewState);
                    nuevaLinea.DatareaId = linea.DatareaId;

                    //Avanzo la fecha tantos dias como corresponda...
                    fechaTmp                 = linea.Fecha.Add(diasEnElFuturo)  ;
                    nuevaLinea.Fecha         = fechaTmp                         ;
                    nuevaLinea.Dia           = fechaTmp.Day                     ;
                    nuevaLinea.DiaSemana     = fechaTmp.ToString("dddd", new CultureInfo("es-ES")).ToUpper().Trim();
                    nuevaLinea.Costo         = linea.Costo                      ;
                    nuevaLinea.CostoOp       = linea.CostoOp                    ;
                    nuevaLinea.CostoOpUni    = linea.CostoOpUni                 ;
                    nuevaLinea.CostoUni      = linea.CostoUni                   ;
                    nuevaLinea.Duracion      = linea.Duracion                   ;
                    nuevaLinea.Hora          = linea.Hora                       ;
                    nuevaLinea.IdentifAviso  = linea.IdentifAviso               ;
                    nuevaLinea.PautaId       = linea.PautaId                    ;
                    nuevaLinea.Salida        = linea.Salida                     ;

                    //Agrego la nueva linea.
                    lineasTmp.Add(nuevaLinea);
                }

                //Junto las dos listas (temporal y la que ya tenia).
                lineasTmp.AddRange(lineas);

                //Ordeno por fecha.
                lineasTmp.Sort(
                    (x, y) => DateTime.Compare(x.Fecha, y.Fecha));

                //Guardo la lista en el Viewstate.
                return lineasTmp;
            }
            else
            {
                return lineas;
            }
        }
Esempio n. 13
0
		public WebPartVerb (string id, WebPartEventHandler serverClickHandler, string clientClickHandler) {
			this.id = id;
			this.serverClickHandler = serverClickHandler;
			this.clientClickHandler = clientClickHandler;
			stateBag = new StateBag ();
			stateBag.Add ("serverClickHandler", serverClickHandler);
			stateBag.Add ("clientClickHandler", clientClickHandler);
		}
 public void beforTest()
 {
     mockery = new Mockery();
     view = mockery.NewMock<ITrackListingView>();
     task = mockery.NewMock<ITrackListingTask>();
     presenter = new TrackListingPresenter(view, task);
     stateBag = new StateBag();
 }
		internal CssStyleCollection (StateBag bag)
		{
			this.bag = bag;
			style = new StateBag ();
			string st_string = bag ["style"] as string;
			if (st_string != null)
				FillStyle (st_string);
		}
Esempio n. 16
0
 /// <devdoc>
 ///    <para>
 ///       Initializes a new instance of the <see cref='System.Web.UI.WebControls.Style'/> class with the
 ///       specified state bag information.  Do not use this constructor if you are overriding
 ///       CreateControlStyle() and are changing some properties on the created style.
 ///    </para>
 /// </devdoc>
 public Style(StateBag bag) {
     statebag = bag;
     marked = false;
     setBits = 0;
     // VSWhidbey 541984: Style inherits from Component and requires finalization, resulting in bad performance
     // When inheriting, if finalization is desired, call GC.ReRegisterForFinalize
     GC.SuppressFinalize(this);
 }
Esempio n. 17
0
		public void IStateManager_Deny_Unrestricted ()
		{
			IStateManager sm = new StateBag ();
			Assert.IsFalse (sm.IsTrackingViewState, "IsTrackingViewState");
			object state = sm.SaveViewState ();
			sm.LoadViewState (state);
			sm.TrackViewState ();
		}
		void EnsureAttributes ()
		{
			if (attributes == null) {
				attrBag = new StateBag (true);
				if (IsTrackingViewState)
					attrBag.TrackViewState ();
				attributes = new AttributeCollection (attrBag);
			}
		}
 public static WebSecurityAddInCollection CreateWebSecurityAddInCollection(WebSecurityAddInData addIns, StateBag viewStateContext, string languageCode)
 {
     WebSecurityAddInCollection ins = new WebSecurityAddInCollection();
     foreach (WebSecurityAddInData.WebSecurityAddInsRow row in addIns.WebSecurityAddIns)
     {
         ins.Add(Create(row, viewStateContext, languageCode));
     }
     return ins;
 }
Esempio n. 20
0
		public void SetValueToNull ()
		{
			StateBag sb = new StateBag ();
			sb ["a"] = "a";
			Assert.AreEqual ("a", sb ["a"], "#1");
			sb ["a"] = null;
			Assert.IsNull (sb ["a"], "#2");
			Assert.AreEqual (0, sb.Count, "#3");
		}
Esempio n. 21
0
 public static string ViewStateString(System.Web.UI.StateBag viewState, string parmName)
 {
     try
     {
         return((viewState[parmName]).ToString().Trim());
     }
     catch
     { }
     return("");
 }
Esempio n. 22
0
 public static int ViewStateInt(System.Web.UI.StateBag viewState, string parmName, int minValue = 0, int maxValue = int.MaxValue)
 {
     try
     {
         return(IntValue((viewState[parmName]).ToString().Trim(), minValue, maxValue));
     }
     catch
     { }
     return(0);
 }
Esempio n. 23
0
		public void SetValueToNull2 ()
		{
			StateBag sb = new StateBag ();
			sb ["a"] = "a";
			Assert.AreEqual ("a", sb ["a"], "#1");
			((IStateManager) sb).TrackViewState ();
			sb ["a"] = null;
			Assert.IsNull (sb ["a"], "#2");
			Assert.AreEqual (1, sb.Count, "#3");
		}
Esempio n. 24
0
        internal static int NextTempRecId(StateBag viewState)
        {
            if (viewState["TempRecId"] != null)
            {
                int RecId = Convert.ToInt32(viewState["TempRecId"]) + 1;

                viewState.Add("TempRecId", RecId);
                return RecId;
            }
            else
            {
                viewState.Add("TempRecId", 1);
                return 1;
            }
        }
Esempio n. 25
0
		public void Deny_Unrestricted ()
		{
			StateBag bag = new StateBag (true);
			Assert.IsNotNull (bag.Add ("key", "value"), "Add");
			Assert.AreEqual (1, bag.Count, "Count");
			Assert.IsNotNull (bag.GetEnumerator (), "GetEnumerator");
			bag.SetItemDirty ("key", true);
			Assert.IsTrue (bag.IsItemDirty ("key"), "IsItemDirty");
			bag.Remove ("key");

			bag.Clear ();
			bag["key"] = "value";
			Assert.IsNotNull (bag["key"], "this[string]");
			Assert.IsNotNull (bag.Keys, "Keys");
			Assert.IsNotNull (bag.Values, "Values");
			bag.SetDirty (true);
		}
 protected override void LoadViewState(object savedState)
 {
     if (savedState != null)
     {
         Pair pair = (Pair) savedState;
         base.LoadViewState(pair.First);
         if (pair.Second != null)
         {
             if (this.attributeStorage == null)
             {
                 this.attributeStorage = new StateBag(true);
                 this.attributeStorage.TrackViewState();
             }
             this.attributeStorage.LoadViewState(pair.Second);
         }
     }
 }
Esempio n. 27
0
		public void IDictionary_Deny_Unrestricted ()
		{
			IDictionary d = new StateBag ();
			d.Add ("key", "value");
			Assert.IsTrue (d.Contains ("key"), "Contains");
			Assert.AreEqual (1, d.Count, "Count");
			d.Remove ("key");
			d["key"] = "value";
			Assert.AreEqual ("value", d["key"], "this[string]");
			d.Clear ();
			Assert.IsFalse (d.IsFixedSize, "IsFixedSize");
			Assert.IsFalse (d.IsReadOnly, "IsReadOnly");

			ICollection c = (d as ICollection);
			Assert.IsFalse (c.IsSynchronized, "IsSynchronized");
			Assert.IsNotNull (c.SyncRoot, "SyncRoot");
		}
Esempio n. 28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="SB"></param>
 /// <param name="sortExpression"></param>
 public void SetSort(System.Web.UI.StateBag SB, string sortExpression)
 {
     if (SB["sort"] == null)
     {
         SB["sort"] = sortExpression;
         SB["desc"] = "";
     }
     else if ((SB["sort"].ToString() + SB["desc"].ToString()).ToString() == sortExpression)
     {
         SB["sort"] = sortExpression;
         SB["desc"] = " DESC";
     }
     else
     {
         SB["sort"] = sortExpression;
         SB["desc"] = "";
     }
 }
Esempio n. 29
0
 /// <summary>
 /// 设置排序
 /// </summary>
 /// <param name="SB"></param>
 /// <param name="e"></param>
 public void SetSort(System.Web.UI.StateBag SB, DataGridSortCommandEventArgs e)
 {
     if (SB["sort"] == null)
     {
         SB["sort"] = e.SortExpression;
         SB["desc"] = "";
     }
     else if ((SB["sort"].ToString() + SB["desc"].ToString()).ToString() == e.SortExpression)
     {
         SB["sort"] = e.SortExpression;
         SB["desc"] = " DESC";
     }
     else
     {
         SB["sort"] = e.SortExpression;
         SB["desc"] = "";
     }
 }
Esempio n. 30
0
 public string getSortDirection(System.Web.UI.StateBag viewState, string sortExpression)
 {
     // If the GridView is sorted for the first time or sorting is being done on a new column,
     // then set the sort direction to "ASC" in ViewState.
     if (viewState["SortDirection"] == null || viewState["SortExpression"].ToString() != sortExpression)
     {
         viewState["SortDirection"] = "ASC";
     }
     // Othewise if the same column is clicked for sorting more than once, then toggle its SortDirection.
     else if (viewState["SortDirection"].ToString() == "ASC")
     {
         viewState["SortDirection"] = "DESC";
     }
     else if (viewState["SortDirection"].ToString() == "DESC")
     {
         viewState["SortDirection"] = "ASC";
     }
     return(viewState["SortDirection"].ToString());
 }
        public static void Serialize(object value, StateBag state)
        {
            Type typ = value.GetType();

            //Parse all the Public instance properties
            foreach (PropertyInfo member in typ.GetProperties(MemberBindingFlags))
            {
                //Determine if they are attributed with a ViewState Attribute
                ViewStateAttribute attr = member.GetCustomAttributes(typeof (ViewStateAttribute), true).OfType<ViewStateAttribute>().FirstOrDefault();
                if ((attr != null))
                {
                    //Add property to ViewState bag
                    string viewStateKey = attr.ViewStateKey;
                    if (string.IsNullOrEmpty(viewStateKey))
                    {
                        //Use class member's name for Key
                        viewStateKey = member.Name;
                    }

                    state[viewStateKey] = member.GetValue(value, null);
                }
            }
        }
Esempio n. 32
0
    public string ToString(string preserve, string removeList, System.Web.UI.StateBag viewState)
    {
        HttpRequest       Request = HttpContext.Current.Request;
        HttpServerUtility Server  = HttpContext.Current.Server;

        string[] List;

        if (removeList == "")
        {
            List = new string[1];
        }
        else
        {
            List = removeList.Split(new Char[] { ';' });
        }

        if (preserve == "All" || preserve == "GET")
        {
            if (viewState != null)
            {
                int      length = viewState.Count;
                string[] keys   = new string[length];
                System.Web.UI.StateItem[] values = new System.Web.UI.StateItem[length];
                viewState.Keys.CopyTo(keys, 0);
                viewState.Values.CopyTo(values, 0);
                string cvalue = "";
                for (int i = 0; i < length; i++)
                {
                    if (values[i].Value != null)
                    {
                        cvalue = values[i].Value.ToString();
                    }
                    else
                    {
                        cvalue = "";
                    }
                    string ckey = "";
                    if (keys[i].EndsWith("SortField") && cvalue != "Default")
                    {
                        ckey = keys[i].Replace("SortField", "Order");
                    }
                    if (keys[i].EndsWith("SortDir"))
                    {
                        ckey = keys[i].Replace("SortDir", "Dir");
                    }
                    if (keys[i].EndsWith("PageNumber") && cvalue != "1")
                    {
                        ckey = keys[i].Replace("PageNumber", "Page");
                    }
                    if (ckey != "" && Array.IndexOf(List, ckey) < 0)
                    {
                        if (this[ckey] == null)
                        {
                            Add(ckey, cvalue);
                        }
                        else
                        {
                            this[ckey] = cvalue;
                        }
                    }
                }
            }
            for (int i = 0; i < Request.QueryString.Count; i++)
            {
                if (Array.IndexOf(List, Request.QueryString.AllKeys[i]) < 0 && BaseGet(Request.QueryString.AllKeys[i]) == null)
                {
                    foreach (string val in Request.QueryString.GetValues(i))
                    {
                        Add(Request.QueryString.AllKeys[i], Server.UrlEncode(val));
                    }
                }
            }
        }
        if (preserve == "All" || preserve == "POST")
        {
            for (int i = 0; i < Request.Form.Count; i++)
            {
                if (Array.IndexOf(List, Request.Form.AllKeys[i]) < 0 &&
                    Request.Form.AllKeys[i] != "__EVENTTARGET" &&
                    Request.Form.AllKeys[i] != "__EVENTARGUMENT" &&
                    Request.Form.AllKeys[i] != "__VIEWSTATE" &&
                    BaseGet(Request.Form.AllKeys[i]) == null)
                {
                    foreach (string val in Request.Form.GetValues(i))
                    {
                        Add(Request.Form.AllKeys[i], Server.UrlEncode(val));
                    }
                }
            }
        }

        return(ToString(""));
    }
Esempio n. 33
0
		public MenuItemStyle (StateBag bag)
			: base (bag)
		{
		}
 public AttributeCollection(StateBag bag)
 {
 }
 internal CssStyleCollection(StateBag state)
 {
     this._state = state;
 }
 public BorderedPanelStyle(StateBag bag)
     : base(bag)
 {
 }
Esempio n. 37
0
 ///<summary>
 ///Removes any state maintaining objects that are used to track sort orders in the gridview CreateSortArrows method
 ///</summary>
 ///<param name="viewState"></param>
 ///<remarks></remarks>
 public static void ClearSortArrowState(StateBag viewState)
 {
     viewState.Remove("EntitySortProperty");
     viewState.Remove("EntitySortDirection");
 }
Esempio n. 38
0
 public AttributeCollection(StateBag bag)
 {
     this.bag = bag;
 }
Esempio n. 39
0
 /// <summary>
 /// 初始化排序功能
 /// </summary>
 /// <param name="viewState">用來存放排序條件的 viewState </param>
 public GVSortHelper(System.Web.UI.StateBag viewState)
 {
     this._viewState = viewState;
 }
Esempio n. 40
0
 public void Dispose() // 只是為了能用 using 語法實作 dispose
 {
     this._viewState = null;
 }
Esempio n. 41
0
 public GVSortHelper(System.Web.UI.StateBag viewState, string gridviewID)
 {
     this._viewState = viewState;
     this._gvId      = gridviewID;
 }
Esempio n. 42
0
 public ViewStateProxy(XControl control, StateBag viewState)
 {
     this.control = control;
     this.ViewState = viewState;
 }
Esempio n. 43
0
		public TableStyle (StateBag bag)
			: base (bag)
		{
		}
Esempio n. 44
0
        ///<summary>
        ///Takes a GridView object and attaches a suitable sort artist to the headerrow cells of any sortable columns
        ///</summary>
        ///<param name="gridView">The <see cref="System.Web.UI.WebControls.GridView" /> object whose headerrow cells are to be managed</param>
        ///<param name="defaultSortExpression">The default sort expression of the GridView data as <see cref="System.String" /></param>
        ///<param name="defaultSortDirection">The default sort direction of the GridView data as <see cref="System.Web.UI.WebControls.SortDirection" /></param>
        ///<param name="sortImagesFolder">The folder where the sort images are stored as <see cref="System.String" />. The sort images must be named sort_ascending.gif, sort_descending.gif and sort_unsorted.gif.</param>
        ///<param name="viewState">The page ViewState object that will allow tracking of the current sortorder. Only used when the sort has been performed using <see cref="William.Model.Entity.EntitySorter(Of T)" /></param>
        ///<param name="throwEmtpyDataException">If true an error is thrown if the gridview contains no data</param>
        ///<remarks>Must be run from within the PreRender event of the GridView so that the HeaderRow cells are created</remarks>
        public static void CreateSortArrows(System.Web.UI.WebControls.GridView gridView, string defaultSortExpression, SortDirection defaultSortDirection, string sortImagesFolder, StateBag viewState, bool throwEmtpyDataException)
        {

            // Check to see if the GridView contains rows of data. If there is no data throw an exception or exit the subroutine
            if (gridView.Rows.Count == 0)
                if (throwEmtpyDataException)
                    throw new Exception(string.Format("The GridView \"{0}\" has no data.{1}Please ensure that you check the GridView has rows of data before running the CreateSortArrows shared method.", gridView.ID, Environment.NewLine));
                else
                    return;
            
            // Check to see that the GridView has been created before working with the HeaderRow cells
            // Although the RowCreated event fires after every row is created the actual GridView is
            // not created until after all rows have been created
            if (gridView.HeaderRow == null)
                throw new Exception(string.Format("The GridView \"{0}\" has not yet been created.{1}Please check that you are running the CreateSortArrows shared method from within the GridView's PreRender event handler.", gridView.ID, Environment.NewLine));
            
            // Enumerate the columns and create the arrows for each sortable column
            foreach(DataControlField dcf in gridView.Columns)
            {
                if (!string.IsNullOrEmpty(dcf.SortExpression))
                {

                    string sortDirection = string.Empty;

                    // Work out which arrow is to be used for this column. If viewstate is passed in
                    // use William.Model.Data.EntitySorter's custom tracking, otherwise use the properties of the gridview
                    if (viewState != null)
                    {

                        if (dcf.SortExpression == (string)viewState["EntitySortProperty"])
                            sortDirection = ((SortDirection)viewState["EntitySortDirection"]).ToString();
                        else if (string.IsNullOrEmpty((string)viewState["EntitySortProperty"]) && dcf.SortExpression == defaultSortExpression)
                        {
                            sortDirection = defaultSortDirection.ToString();
                            viewState["EntitySortProperty"] = defaultSortExpression;
                            viewState["EntitySortDirection"] = defaultSortDirection;
                        }
                        else
                            sortDirection = "Unsorted";

                    } 
                    else
                    {

                        if (dcf.SortExpression == gridView.SortExpression)
                            sortDirection = gridView.SortDirection.ToString();
                        else if (string.IsNullOrEmpty(gridView.SortExpression) && dcf.SortExpression == defaultSortExpression)
                            sortDirection = defaultSortDirection.ToString();
                        else
                            sortDirection = "Unsorted";

                    }

                    Image sortImage = new Image();
                    sortImage.ImageUrl = string.Format(sortImagesFolder + "sort_{0}.gif", sortDirection.ToLower());
                    sortImage.AlternateText = string.Format("Sort Order: {0}", sortDirection);
                    sortImage.ToolTip = string.Format("Sort Order: {0}", sortDirection);
                    sortImage.Style.Add("margin-left", "5px");

                    gridView.HeaderRow.Cells[gridView.Columns.IndexOf(dcf)].Controls.Add(sortImage);

                }
            }

        } // CreateSortArrows