2 // System.Web.UI.WebControls.HyperLinkColumn.cs
4 // Author: Duncan Mak (duncan@ximian.com)
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:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
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
;
30 using System
.Security
.Permissions
;
32 namespace System
.Web
.UI
.WebControls
{
35 [AspNetHostingPermissionAttribute (SecurityAction
.LinkDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
36 [AspNetHostingPermissionAttribute (SecurityAction
.InheritanceDemand
, Level
= AspNetHostingPermissionLevel
.Minimal
)]
37 public class HyperLinkColumn
: DataGridColumn
39 public HyperLinkColumn ()
44 [WebSysDescription ("")]
45 [WebCategory ("Misc")]
46 public virtual string DataNavigateUrlField
{
48 return ViewState
.GetString ("DataNavigateUrlField", String
.Empty
);
50 set { ViewState ["DataNavigateUrlField"] = value; }
54 [Description("The formatting applied to the value bound to the NavigateUrl property.")]
55 [WebCategory ("Misc")]
56 public virtual string DataNavigateUrlFormatString
{
58 return ViewState
.GetString ("DataNavigateUrlFormatString", String
.Empty
);
60 set { ViewState ["DataNavigateUrlFormatString"] = value; }
64 [WebSysDescription ("")]
65 [WebCategory ("Misc")]
66 public virtual string DataTextField
{
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.")]
75 [WebCategory ("Misc")]
76 public virtual string DataTextFormatString
{
78 return ViewState
.GetString ("DataTextFormatString", String
.Empty
);
80 set { ViewState ["DataTextFormatString"] = value; }
84 [WebSysDescription ("")]
85 [WebCategory ("Misc")]
86 public virtual string NavigateUrl
{
88 return ViewState
.GetString ("NavigateUrl", String
.Empty
);
90 set { ViewState ["NavigateUrl"] = value; }
94 [WebSysDescription ("")]
95 [WebCategory ("Misc")]
96 public virtual string Target
{
98 return ViewState
.GetString ("Target", String
.Empty
);
100 set { ViewState ["Target"] = value; }
104 [WebSysDescription ("")]
105 [WebCategory ("Misc")]
106 public virtual string Text
{
108 return ViewState
.GetString ("Text", String
.Empty
);
110 set { ViewState ["Text"] = value; }
113 protected virtual string FormatDataNavigateUrlValue (object value)
115 string format
= DataNavigateUrlFormatString
;
119 return DataBinder
.FormatResult (value, format
);
122 protected virtual string FormatDataTextValue (object value)
124 string format
= DataTextFormatString
;
128 return DataBinder
.FormatResult (value, format
);
131 public override void 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
));
145 ctrl
.NavigateUrl
= NavigateUrl
;
147 if (DataTextField
!= "")
148 ctrl
.Text
= FormatDataTextValue (DataBinder
.Eval (item
.DataItem
, DataTextField
));
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
);
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
168 case ListItemType
.Item
:
169 case ListItemType
.EditItem
:
170 case ListItemType
.AlternatingItem
:
171 cell
.DataBinding
+= new EventHandler(ItemDataBinding
);
172 cell
.Controls
.Add (new HyperLink ());