(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web.UI.WebControls / HyperLinkColumn.cs
blobfb4fce79efb0e5cb7ea36e1bc11091d75ab52ac8
1 //
2 // System.Web.UI.WebControls.HyperLinkColumn.cs
3 //
4 // Authors:
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
8 //
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 // (C) Gaurav Vaish (2002)
11 // (C) 2003 Andreas Nahr
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 //
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 //
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System;
36 using System.ComponentModel;
37 using System.Web;
38 using System.Web.UI;
40 namespace System.Web.UI.WebControls
42 public class HyperLinkColumn: DataGridColumn
44 PropertyDescriptor textFieldDescriptor;
45 PropertyDescriptor urlFieldDescriptor;
47 public HyperLinkColumn ()
51 [DefaultValue (""), WebCategory ("Misc")]
52 [WebSysDescription ("The field that gets data-bound to the NavigateUrl.")]
53 public virtual string DataNavigateUrlField {
54 get {
55 object o = ViewState ["DataNavigateUrlField"];
56 if (o != null)
57 return (string) o;
58 return String.Empty;
61 set {
62 ViewState ["DataNavigateUrlField"] = value;
63 OnColumnChanged ();
67 // LAMESPEC should use WebSysDescription as all others do, but MS uses Description here
69 [DefaultValue (""), WebCategory ("Misc")]
70 [Description ("The formatting rule for the text content that gets data-bound to the NavigateUrl.")]
71 public virtual string DataNavigateUrlFormatString {
72 get {
73 object o = ViewState ["DataNavigateUrlFormatString"];
74 if (o != null)
75 return (string) o;
76 return String.Empty;
79 set {
80 ViewState ["DataNavigateUrlFormatString"] = value;
81 OnColumnChanged ();
85 [DefaultValue (""), WebCategory ("Misc")]
86 [WebSysDescription ("The field that gets data-bound to the Text property.")]
87 public virtual string DataTextField {
88 get {
89 object o = ViewState ["DataTextField"];
90 if (o != null)
91 return (string) o;
92 return String.Empty;
94 set {
95 ViewState ["DataTextField"] = value;
96 OnColumnChanged ();
100 // LAMESPEC should use WebSysDescription as all others do, but MS uses Description here
102 [DefaultValue (""), WebCategory ("Misc")]
103 [Description ("The formatting rule for the text content that gets data-bound to the Text property.")]
104 public virtual string DataTextFormatString {
105 get {
106 object o = ViewState ["DataTextFormatString"];
107 if (o != null)
108 return (string) o;
109 return String.Empty;
112 set {
113 ViewState ["DataTextFormatString"] = value;
114 OnColumnChanged ();
118 [DefaultValue (""), WebCategory ("Misc")]
119 [WebSysDescription ("The URL that this hyperlink links to.")]
120 public virtual string NavigateUrl {
121 get {
122 object o = ViewState ["NavigateUrl"];
123 if (o != null)
124 return (string) o;
125 return String.Empty;
128 set {
129 ViewState ["NavigateUrl"] = value;
130 OnColumnChanged ();
134 [DefaultValue (""), WebCategory ("Misc")]
135 [WebSysDescription ("The target frame in which the NavigateUrl property should be opened.")]
136 public virtual string Target {
137 get {
138 object o = ViewState ["Target"];
139 if (o != null)
140 return (string) o;
141 return String.Empty;
144 set {
145 ViewState ["Target"] = value;
146 OnColumnChanged ();
150 [DefaultValue (""), WebCategory ("Misc")]
151 [WebSysDescription ("The Text for the hyperlink.")]
152 public virtual string Text {
153 get {
154 object o = ViewState ["Text"];
155 if (o != null)
156 return (string) o;
157 return String.Empty;
160 set {
161 ViewState ["Text"] = value;
162 OnColumnChanged ();
166 public override void Initialize ()
168 textFieldDescriptor = null;
169 urlFieldDescriptor = null;
170 base.Initialize ();
173 public override void InitializeCell (TableCell cell, int columnIndex, ListItemType itemType)
175 base.InitializeCell (cell, columnIndex, itemType);
177 if (itemType != ListItemType.Header && itemType != ListItemType.Footer) {
178 HyperLink toDisplay = new HyperLink ();
179 toDisplay.Text = Text;
180 toDisplay.NavigateUrl = NavigateUrl;
181 toDisplay.Target = Target;
183 if (DataTextField.Length > 0 || DataNavigateUrlField.Length > 0)
184 toDisplay.DataBinding += new EventHandler (OnDataBindHyperLinkColumn);
186 cell.Controls.Add (toDisplay);
190 private void OnDataBindHyperLinkColumn (object sender, EventArgs e)
192 HyperLink link = (HyperLink) sender;
193 object item = ((DataGridItem) link.NamingContainer).DataItem;
195 PropertyDescriptorCollection properties = TypeDescriptor.GetProperties (item);
196 if (textFieldDescriptor == null)
197 textFieldDescriptor = properties.Find (DataTextField, true);
199 if (urlFieldDescriptor == null)
200 urlFieldDescriptor = properties.Find (DataNavigateUrlField, true);
202 if (DataTextField.Length > 0 && textFieldDescriptor == null && !DesignMode)
203 throw new HttpException (HttpRuntime.FormatResourceString (
204 "Field_Not_Found", DataTextField));
206 if (DataNavigateUrlField.Length > 0 && urlFieldDescriptor == null && !DesignMode)
207 throw new HttpException (HttpRuntime.FormatResourceString (
208 "Field_Not_Found", DataNavigateUrlField));
210 if (textFieldDescriptor != null) {
211 link.Text = FormatDataTextValue (textFieldDescriptor.GetValue (item));
212 } else {
213 link.Text = Text;
216 if (urlFieldDescriptor != null) {
217 link.NavigateUrl = FormatDataNavigateUrlValue (urlFieldDescriptor.GetValue (item));
218 return;
221 if (DataNavigateUrlField.Length != 0 && DesignMode)
222 link.NavigateUrl = "url";
225 protected virtual string FormatDataNavigateUrlValue (object dataUrlValue)
227 if (dataUrlValue == null)
228 return String.Empty;
230 string retVal;
231 if (DataNavigateUrlFormatString.Length > 0) {
232 retVal = String.Format (DataNavigateUrlFormatString, dataUrlValue);
233 } else {
234 retVal = dataUrlValue.ToString ();
237 return retVal;
240 protected virtual string FormatDataTextValue (object dataTextValue)
242 if (dataTextValue == null)
243 return String.Empty;
245 string retVal;
246 if (DataTextFormatString.Length > 0) {
247 retVal = String.Format (DataTextFormatString, dataTextValue);
248 } else {
249 retVal = dataTextValue.ToString ();
252 return retVal;