2 // System.Web.UI.WebControls.DataGridColumn.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 // (C) Gaurav Vaish (2002)
9 // (C) 2003 Andreas Nahr
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.ComponentModel;
38 namespace System.Web.UI.WebControls
40 [TypeConverter(typeof(ExpandableObjectConverter))]
41 public abstract class DataGridColumn : IStateManager
43 private StateBag viewState;
45 private TableItemStyle footerStyle;
46 private TableItemStyle headerStyle;
47 private TableItemStyle itemStyle;
49 private DataGrid owner;
50 private bool designMode;
52 public DataGridColumn()
54 viewState = new StateBag();
57 internal TableItemStyle FooterStyleInternal
65 internal TableItemStyle HeaderStyleInternal
73 internal TableItemStyle ItemStyleInternal
81 [DefaultValue (null), WebCategory ("Misc")]
82 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
83 [PersistenceMode (PersistenceMode.InnerProperty)]
84 [WebSysDescription ("The style applied to the footer of this column.")]
85 public virtual TableItemStyle FooterStyle
89 if(footerStyle == null)
91 footerStyle = new TableItemStyle();
92 if(IsTrackingViewState)
94 footerStyle.TrackViewState();
101 [DefaultValue (null), WebCategory ("Misc")]
102 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
103 [PersistenceMode (PersistenceMode.InnerProperty)]
104 [WebSysDescription ("The style applied to the header of this column.")]
105 public virtual TableItemStyle HeaderStyle
109 if(headerStyle == null)
111 headerStyle= new TableItemStyle();
112 if(IsTrackingViewState)
114 headerStyle.TrackViewState();
121 [DefaultValue (null), WebCategory ("Misc")]
122 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
123 [PersistenceMode (PersistenceMode.InnerProperty)]
124 [WebSysDescription ("The style applied to the rows of this column.")]
125 public virtual TableItemStyle ItemStyle
129 if(itemStyle == null)
131 itemStyle = new TableItemStyle();
132 if(IsTrackingViewState)
134 itemStyle.TrackViewState();
141 [DefaultValue (""), WebCategory ("Misc")]
142 [WebSysDescription ("The text within the footer of this column.")]
143 public virtual string FooterText
147 object o = ViewState["FooterText"];
156 ViewState["FooterText"] = value;
161 [DefaultValue (""), WebCategory ("Misc")]
162 [WebSysDescription ("The URL to an image that is displayed in the header of this column.")]
163 public virtual string HeaderImageUrl
167 object o = ViewState["HeaderImageUrl"];
176 ViewState["HeaderImageUrl"] = value;
181 [DefaultValue (""), WebCategory ("Misc")]
182 [WebSysDescription ("The text within the header of this column.")]
183 public virtual string HeaderText
187 object o = ViewState["HeaderText"];
196 ViewState["HeaderText"] = value;
201 [DefaultValue (""), WebCategory ("Misc")]
202 [WebSysDescription ("An expression that determines how the colum should be sorted.")]
203 public virtual string SortExpression
207 object o = ViewState["SortExpression"];
216 ViewState["SortExpression"] = value;
221 [DefaultValue (true), WebCategory ("Misc")]
222 [WebSysDescription ("The visibility of this column.")]
227 object o = ViewState["Visible"];
236 ViewState["Visible"] = value;
241 public virtual void Initialize()
243 if(owner != null && owner.Site != null)
245 designMode = owner.Site.DesignMode;
249 public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
253 case ListItemType.Header : InitializeCellHeader(cell, columnIndex);
255 case ListItemType.Footer : InitializeCellFooter(cell, columnIndex);
257 default : if (ItemStyleInternal != null)
258 cell.ApplyStyle (ItemStyleInternal);
263 private void InitializeCellHeader(TableCell cell, int columnIndex)
265 WebControl ctrl = null;
267 string sortExpr = "";
268 ImageButton headButton;
270 LinkButtonInternal link;
274 sort = owner.AllowSorting;
278 sortExpr = SortExpression;
279 if(sortExpr.Length == 0)
284 if(HeaderImageUrl.Length > 0)
288 headButton = new ImageButton();
289 headButton.ImageUrl = HeaderImageUrl;
290 headButton.CommandName = "Sort";
291 headButton.CommandArgument = sortExpr;
292 headButton.CausesValidation = false;
296 headImage = new Image();
297 headImage.ImageUrl = HeaderImageUrl;
304 link = new LinkButtonInternal();
305 link.Text = HeaderText;
306 link.CommandName = "Sort";
307 link.CommandArgument = sortExpr;
308 link.CausesValidation = false;
312 if(HeaderText.Length > 0)
314 cell.Text = HeaderText;
317 cell.Text = " ";
323 cell.Controls.Add(ctrl);
325 if (HeaderStyleInternal != null)
326 cell.ApplyStyle (HeaderStyleInternal);
329 private void InitializeCellFooter(TableCell cell, int columnIndex)
331 cell.Text = (FooterText.Length > 0 ? FooterText : " ");
332 if (FooterStyleInternal != null)
333 cell.ApplyStyle (FooterStyleInternal);
336 public override string ToString()
341 protected bool DesignMode
349 protected DataGrid Owner
357 protected StateBag ViewState
368 protected virtual void OnColumnChanged()
372 owner.OnColumnsChanged();
376 internal void SetOwner (DataGrid datagrid)
381 protected virtual object SaveViewState()
383 object[] states = new object[4];
384 states[0] = ViewState.SaveViewState();
385 states[1] = (footerStyle == null ? null : footerStyle.SaveViewState());
386 states[2] = (headerStyle == null ? null : headerStyle.SaveViewState());
387 states[3] = (itemStyle == null ? null : itemStyle.SaveViewState());
389 for (int i = 0; i < states.Length; i++) {
390 if (states [i] != null)
396 protected virtual void LoadViewState(object savedState)
398 if (savedState == null)
401 object[] states = (object[]) savedState;
402 ViewState.LoadViewState (states [0]);
403 FooterStyle.LoadViewState (states [1]);
404 HeaderStyle.LoadViewState (states [2]);
405 ItemStyle.LoadViewState (states [3]);
408 protected virtual void TrackViewState()
411 ViewState.TrackViewState();
412 if(footerStyle != null)
414 footerStyle.TrackViewState();
416 if(headerStyle != null)
418 headerStyle.TrackViewState();
420 if(itemStyle != null)
422 itemStyle.TrackViewState();
426 protected bool IsTrackingViewState
434 void IStateManager.LoadViewState(object savedState)
436 LoadViewState(savedState);
439 object IStateManager.SaveViewState()
441 return SaveViewState();
444 void IStateManager.TrackViewState()
449 bool IStateManager.IsTrackingViewState
453 return IsTrackingViewState;