2010-03-02 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Web / System.Web.UI.WebControls / HyperLinkColumn.cs
blob3b4e78253ecdd71c76ad71b084a7d6cd205de5f6
1 //
2 // System.Web.UI.WebControls.HyperLinkColumn.cs
3 //
4 // Author: Duncan Mak (duncan@ximian.com)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
28 using System.ComponentModel;
29 using System.Data;
30 using System.Security.Permissions;
32 namespace System.Web.UI.WebControls {
34 // CAS
35 [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
36 [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
37 public class HyperLinkColumn : DataGridColumn
39 public HyperLinkColumn ()
43 [DefaultValue("")]
44 [WebSysDescription ("")]
45 [WebCategory ("Misc")]
46 public virtual string DataNavigateUrlField {
47 get {
48 return ViewState.GetString ("DataNavigateUrlField", String.Empty);
50 set { ViewState ["DataNavigateUrlField"] = value; }
53 [DefaultValue("")]
54 [Description("The formatting applied to the value bound to the NavigateUrl property.")]
55 [WebCategory ("Misc")]
56 public virtual string DataNavigateUrlFormatString {
57 get {
58 return ViewState.GetString ("DataNavigateUrlFormatString", String.Empty);
60 set { ViewState ["DataNavigateUrlFormatString"] = value; }
63 [DefaultValue("")]
64 [WebSysDescription ("")]
65 [WebCategory ("Misc")]
66 public virtual string DataTextField {
67 get {
68 return ViewState.GetString ("DataTextField", String.Empty);
70 set { ViewState ["DataTextField"] = value; }
73 [Description("The formatting applied to the value bound to the Text property.")]
74 [DefaultValue("")]
75 [WebCategory ("Misc")]
76 public virtual string DataTextFormatString {
77 get {
78 return ViewState.GetString ("DataTextFormatString", String.Empty);
80 set { ViewState ["DataTextFormatString"] = value; }
83 [DefaultValue("")]
84 [WebSysDescription ("")]
85 [WebCategory ("Misc")]
86 public virtual string NavigateUrl {
87 get {
88 return ViewState.GetString ("NavigateUrl", String.Empty);
90 set { ViewState ["NavigateUrl"] = value; }
93 [DefaultValue("")]
94 [WebSysDescription ("")]
95 [WebCategory ("Misc")]
96 public virtual string Target {
97 get {
98 return ViewState.GetString ("Target", String.Empty);
100 set { ViewState ["Target"] = value; }
103 [DefaultValue("")]
104 [WebSysDescription ("")]
105 [WebCategory ("Misc")]
106 public virtual string Text {
107 get {
108 return ViewState.GetString ("Text", String.Empty);
110 set { ViewState ["Text"] = value; }
113 protected virtual string FormatDataNavigateUrlValue (object value)
115 string format = DataNavigateUrlFormatString;
116 if (format == "")
117 format = null;
119 return DataBinder.FormatResult (value, format);
122 protected virtual string FormatDataTextValue (object value)
124 string format = DataTextFormatString;
125 if (format == "")
126 format = null;
128 return DataBinder.FormatResult (value, format);
131 public override void Initialize ()
133 base.Initialize ();
136 void ItemDataBinding (object sender, EventArgs args)
138 TableCell cell = (TableCell)sender;
139 HyperLink ctrl = (HyperLink)cell.Controls[0];
140 DataGridItem item = (DataGridItem)cell.NamingContainer;
142 if (DataNavigateUrlField != "")
143 ctrl.NavigateUrl = FormatDataNavigateUrlValue (DataBinder.Eval (item.DataItem, DataNavigateUrlField));
144 else
145 ctrl.NavigateUrl = NavigateUrl;
147 if (DataTextField != "")
148 ctrl.Text = FormatDataTextValue (DataBinder.Eval (item.DataItem, DataTextField));
149 else
150 ctrl.Text = Text;
152 ctrl.Target = Target;
155 public override void InitializeCell (TableCell cell, int column_index, ListItemType item_type)
157 base.InitializeCell (cell, column_index, item_type);
159 switch (item_type)
161 case ListItemType.Separator:
162 case ListItemType.Pager:
163 case ListItemType.Footer:
164 case ListItemType.Header: {
165 // Base handles header and footer, dunno about the others
166 return;
168 case ListItemType.Item:
169 case ListItemType.EditItem:
170 case ListItemType.AlternatingItem:
171 cell.DataBinding += new EventHandler(ItemDataBinding);
172 cell.Controls.Add (new HyperLink ());
173 break;