2 // System.Web.UI.WebControls.DataGridColumn.cs
5 // Dick Porter <dick@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.ComponentModel;
31 using System.Security.Permissions;
33 namespace System.Web.UI.WebControls {
36 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
39 [TypeConverter (typeof (System.ComponentModel.ExpandableObjectConverter))]
40 public abstract class DataGridColumn : IStateManager
44 bool tracking_viewstate;
47 TableItemStyle footer_style;
48 TableItemStyle header_style;
49 TableItemStyle item_style;
58 viewstate = new StateBag ();
62 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
63 [PersistenceMode (PersistenceMode.InnerProperty)]
64 [WebSysDescription ("")]
65 [WebCategory ("Misc")]
66 public virtual TableItemStyle FooterStyle
69 if (footer_style == null) {
70 footer_style = new TableItemStyle ();
72 if (tracking_viewstate) {
73 footer_style.TrackViewState ();
77 return (footer_style);
82 [WebSysDescription ("")]
83 [WebCategory ("Misc")]
84 public virtual string FooterText
87 return (viewstate.GetString ("FooterText",
91 viewstate["FooterText"] = value;
96 [WebSysDescription ("")]
97 [WebCategory ("Misc")]
101 public virtual string HeaderImageUrl
104 return (viewstate.GetString ("HeaderImageUrl",
108 viewstate["HeaderImageUrl"] = value;
112 [DefaultValue (null)]
113 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
114 [PersistenceMode (PersistenceMode.InnerProperty)]
115 [WebSysDescription ("")]
116 [WebCategory ("Misc")]
117 public virtual TableItemStyle HeaderStyle
120 if (header_style == null) {
121 header_style = new TableItemStyle ();
123 if (tracking_viewstate) {
124 header_style.TrackViewState ();
128 return (header_style);
133 [WebSysDescription ("")]
134 [WebCategory ("Misc")]
135 public virtual string HeaderText
138 return (viewstate.GetString ("HeaderText",
142 viewstate["HeaderText"] = value;
146 [DefaultValue (null)]
147 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
148 [PersistenceMode (PersistenceMode.InnerProperty)]
149 [WebSysDescription ("")]
150 [WebCategory ("Misc")]
151 public virtual TableItemStyle ItemStyle
154 if (item_style == null) {
155 item_style = new TableItemStyle ();
157 if (tracking_viewstate) {
158 item_style.TrackViewState ();
167 [WebSysDescription ("")]
168 [WebCategory ("Misc")]
169 public virtual string SortExpression
172 return (viewstate.GetString ("SortExpression",
176 viewstate["SortExpression"] = value;
180 [DefaultValue (true)]
181 [WebSysDescription ("")]
182 [WebCategory ("Misc")]
186 return (viewstate.GetBool ("Visible",
190 viewstate["Visible"] = value;
194 public virtual void Initialize ()
196 if (owner != null && owner.Site != null) {
197 design = owner.Site.DesignMode;
201 internal class ForeColorLinkButton : LinkButton {
202 Color GetForeColor (WebControl control)
207 // don't go beyond the container table.
208 if (control is Table)
209 return control.ControlStyle.ForeColor;
211 Color color = control.ControlStyle.ForeColor;
212 if (color != Color.Empty)
215 return GetForeColor ((WebControl) control.Parent);
223 override void Render (HtmlTextWriter writer)
225 Color color = GetForeColor (this);
226 if (color != Color.Empty)
228 base.Render (writer);
232 public virtual void InitializeCell (TableCell cell,
234 ListItemType itemType)
237 case ListItemType.Header:
239 /* If sorting is enabled, add a
240 * LinkButton or an ImageButton
241 * (depending on HeaderImageUrl).
243 * If sorting is disabled, the
244 * HeaderText or an Image is displayed
245 * (depending on HeaderImageUrl).
247 * If neither HeaderText nor
248 * HeaderImageUrl is set, use
251 string sort_ex = SortExpression;
254 sort_ex.Length > 0) {
255 sort = owner.AllowSorting;
258 string image_url = HeaderImageUrl;
259 if (image_url.Length > 0) {
261 ImageButton butt = new ImageButton ();
264 * resolve this, Image
268 butt.ImageUrl = image_url;
269 butt.CommandName = "Sort";
270 butt.CommandArgument = sort_ex;
272 cell.Controls.Add (butt);
274 Image image = new Image ();
276 image.ImageUrl = image_url;
278 cell.Controls.Add (image);
282 // This one always gets the forecolor of the header_style
283 // from one of the parents, but we can't look it up at this
284 // point, as it can change afterwards.
285 LinkButton link = new ForeColorLinkButton ();
287 link.Text = HeaderText;
288 link.CommandName = "Sort";
289 link.CommandArgument = sort_ex;
291 cell.Controls.Add (link);
293 string text = HeaderText;
294 if (text.Length > 0) {
297 cell.Text = " ";
304 case ListItemType.Footer:
306 /* Display FooterText or */
307 string text = FooterText;
309 if (text.Length > 0) {
312 cell.Text = " ";
324 public override string ToString ()
326 return (String.Empty);
329 protected bool DesignMode
336 protected DataGrid Owner
344 internal TableItemStyle GetStyle (ListItemType type)
346 if (type == ListItemType.Header)
349 if (type == ListItemType.Footer)
355 internal void Set_Owner (DataGrid value)
361 protected StateBag ViewState
368 /* There are no events defined for DataGridColumn, so no
369 * idea what this method is supposed to do
371 protected virtual void OnColumnChanged ()
375 void IStateManager.LoadViewState (object savedState)
377 LoadViewState (savedState);
380 object IStateManager.SaveViewState ()
382 return (SaveViewState ());
385 void IStateManager.TrackViewState ()
390 bool IStateManager.IsTrackingViewState
393 return (IsTrackingViewState);
397 protected virtual void LoadViewState (object savedState)
399 object[] pieces = savedState as object[];
401 if (pieces == null) {
405 if (pieces[0] != null) {
406 viewstate.LoadViewState (pieces[0]);
408 if (pieces[1] != null) {
409 FooterStyle.LoadViewState (pieces[1]);
411 if (pieces[2] != null) {
412 HeaderStyle.LoadViewState (pieces[2]);
414 if (pieces[3] != null) {
415 ItemStyle.LoadViewState (pieces[3]);
419 protected virtual object SaveViewState ()
421 object[] res = new object[4];
423 res[0] = viewstate.SaveViewState ();
425 if (footer_style != null) {
426 res[1] = footer_style.SaveViewState ();
428 if (header_style != null) {
429 res[2] = header_style.SaveViewState ();
431 if (item_style != null) {
432 res[3] = item_style.SaveViewState ();
438 protected virtual void TrackViewState ()
440 tracking_viewstate = true;
442 viewstate.TrackViewState ();
443 if (footer_style != null) {
444 footer_style.TrackViewState ();
446 if (header_style != null) {
447 header_style.TrackViewState ();
449 if (item_style != null) {
450 item_style.TrackViewState ();
454 protected bool IsTrackingViewState
457 return (tracking_viewstate);