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
15 using System.ComponentModel;
17 namespace System.Web.UI.WebControls
19 [TypeConverter(typeof(ExpandableObjectConverter))]
20 public abstract class DataGridColumn : IStateManager
22 private StateBag viewState;
24 private TableItemStyle footerStyle;
25 private TableItemStyle headerStyle;
26 private TableItemStyle itemStyle;
28 private DataGrid owner;
29 private bool designMode;
31 public DataGridColumn()
33 viewState = new StateBag();
36 internal TableItemStyle FooterStyleInternal
44 internal TableItemStyle HeaderStyleInternal
52 internal TableItemStyle ItemStyleInternal
60 [DefaultValue (null), WebCategory ("Misc")]
61 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
62 [PersistenceMode (PersistenceMode.InnerProperty)]
63 [WebSysDescription ("The style applied to the footer of this column.")]
64 public virtual TableItemStyle FooterStyle
68 if(footerStyle == null)
70 footerStyle = new TableItemStyle();
71 if(IsTrackingViewState)
73 footerStyle.TrackViewState();
80 [DefaultValue (null), WebCategory ("Misc")]
81 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
82 [PersistenceMode (PersistenceMode.InnerProperty)]
83 [WebSysDescription ("The style applied to the header of this column.")]
84 public virtual TableItemStyle HeaderStyle
88 if(headerStyle == null)
90 headerStyle= new TableItemStyle();
91 if(IsTrackingViewState)
93 headerStyle.TrackViewState();
100 [DefaultValue (null), WebCategory ("Misc")]
101 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
102 [PersistenceMode (PersistenceMode.InnerProperty)]
103 [WebSysDescription ("The style applied to the rows of this column.")]
104 public virtual TableItemStyle ItemStyle
108 if(itemStyle == null)
110 itemStyle = new TableItemStyle();
111 if(IsTrackingViewState)
113 itemStyle.TrackViewState();
120 [DefaultValue (""), WebCategory ("Misc")]
121 [WebSysDescription ("The text within the footer of this column.")]
122 public virtual string FooterText
126 object o = ViewState["FooterText"];
135 ViewState["FooterText"] = value;
140 [DefaultValue (""), WebCategory ("Misc")]
141 [WebSysDescription ("The URL to an image that is displayed in the header of this column.")]
142 public virtual string HeaderImageUrl
146 object o = ViewState["HeaderImageUrl"];
155 ViewState["HeaderImageUrl"] = value;
160 [DefaultValue (""), WebCategory ("Misc")]
161 [WebSysDescription ("The text within the header of this column.")]
162 public virtual string HeaderText
166 object o = ViewState["HeaderText"];
175 ViewState["HeaderText"] = value;
180 [DefaultValue (""), WebCategory ("Misc")]
181 [WebSysDescription ("An expression that determines how the colum should be sorted.")]
182 public virtual string SortExpression
186 object o = ViewState["SortExpression"];
195 ViewState["SortExpression"] = value;
200 [DefaultValue (true), WebCategory ("Misc")]
201 [WebSysDescription ("The visibility of this column.")]
206 object o = ViewState["Visible"];
215 ViewState["Visible"] = value;
220 public virtual void Initialize()
222 if(owner != null && owner.Site != null)
224 designMode = owner.Site.DesignMode;
228 public virtual void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType)
232 case ListItemType.Header : InitializeCellHeader(cell, columnIndex);
234 case ListItemType.Footer : InitializeCellFooter(cell, columnIndex);
236 default : if (ItemStyleInternal != null)
237 cell.ApplyStyle (ItemStyleInternal);
242 private void InitializeCellHeader(TableCell cell, int columnIndex)
244 WebControl ctrl = null;
246 string sortExpr = "";
247 ImageButton headButton;
249 LinkButtonInternal link;
253 sort = owner.AllowSorting;
257 sortExpr = SortExpression;
258 if(sortExpr.Length == 0)
263 if(HeaderImageUrl.Length > 0)
267 headButton = new ImageButton();
268 headButton.ImageUrl = HeaderImageUrl;
269 headButton.CommandName = "Sort";
270 headButton.CommandArgument = sortExpr;
271 headButton.CausesValidation = false;
275 headImage = new Image();
276 headImage.ImageUrl = HeaderImageUrl;
283 link = new LinkButtonInternal();
284 link.Text = HeaderText;
285 link.CommandName = "Sort";
286 link.CommandArgument = sortExpr;
287 link.CausesValidation = false;
291 if(HeaderText.Length > 0)
293 cell.Text = HeaderText;
296 cell.Text = " ";
302 cell.Controls.Add(ctrl);
304 if (HeaderStyleInternal != null)
305 cell.ApplyStyle (HeaderStyleInternal);
308 private void InitializeCellFooter(TableCell cell, int columnIndex)
310 cell.Text = (FooterText.Length > 0 ? FooterText : " ");
311 if (FooterStyleInternal != null)
312 cell.ApplyStyle (FooterStyleInternal);
315 public override string ToString()
320 protected bool DesignMode
328 protected DataGrid Owner
336 protected StateBag ViewState
347 protected virtual void OnColumnChanged()
351 owner.OnColumnsChanged();
355 internal void SetOwner (DataGrid datagrid)
360 protected virtual object SaveViewState()
362 object[] states = new object[4];
363 states[0] = ViewState.SaveViewState();
364 states[1] = (footerStyle == null ? null : footerStyle.SaveViewState());
365 states[2] = (headerStyle == null ? null : headerStyle.SaveViewState());
366 states[3] = (itemStyle == null ? null : itemStyle.SaveViewState());
368 for (int i = 0; i < states.Length; i++) {
369 if (states [i] != null)
375 protected virtual void LoadViewState(object savedState)
377 if (savedState == null)
380 object[] states = (object[]) savedState;
381 ViewState.LoadViewState (states [0]);
382 FooterStyle.LoadViewState (states [1]);
383 HeaderStyle.LoadViewState (states [2]);
384 ItemStyle.LoadViewState (states [3]);
387 protected virtual void TrackViewState()
390 ViewState.TrackViewState();
391 if(footerStyle != null)
393 footerStyle.TrackViewState();
395 if(headerStyle != null)
397 headerStyle.TrackViewState();
399 if(itemStyle != null)
401 itemStyle.TrackViewState();
405 protected bool IsTrackingViewState
413 void IStateManager.LoadViewState(object savedState)
415 LoadViewState(savedState);
418 object IStateManager.SaveViewState()
420 return SaveViewState();
423 void IStateManager.TrackViewState()
428 bool IStateManager.IsTrackingViewState
432 return IsTrackingViewState;