Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / xsp / System / Web / UI / WebControls / HyperLinkColumn.cs / 1 / HyperLinkColumn.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.Util;
///
/// Creates a column within the containing hyperlinks that
/// navigate to specified URLs.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HyperLinkColumn : DataGridColumn {
private PropertyDescriptor textFieldDesc;
private PropertyDescriptor urlFieldDesc;
///
/// Initializes a new instance of the class.
///
public HyperLinkColumn() {
}
///
/// Gets or sets the field in the DataSource that provides the URL of the page to navigate to.
///
[
WebCategory("Data"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_DataNavigateUrlField)
]
public virtual string DataNavigateUrlField {
get {
object o = ViewState["DataNavigateUrlField"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataNavigateUrlField"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the formatting applied to the
/// property.
///
[
WebCategory("Data"),
DefaultValue(""),
DescriptionAttribute("The formatting applied to the value bound to the NavigateUrl property.")
]
public virtual string DataNavigateUrlFormatString {
get {
object o = ViewState["DataNavigateUrlFormatString"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataNavigateUrlFormatString"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the field in the DataSource that will be used as the source of
/// data for the property.
///
[
WebCategory("Data"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_DataTextField)
]
public virtual string DataTextField {
get {
object o = ViewState["DataTextField"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataTextField"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the formatting applied to the
/// property.
///
[
WebCategory("Data"),
DefaultValue(""),
DescriptionAttribute("The formatting applied to the value bound to the Text property.")
]
public virtual string DataTextFormatString {
get {
object o = ViewState["DataTextFormatString"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataTextFormatString"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the URL to navigate to when the hyperlink is clicked.
///
[
WebCategory("Behavior"),
DefaultValue(""),
UrlProperty(),
WebSysDescription(SR.HyperLinkColumn_NavigateUrl)
]
public virtual string NavigateUrl {
get {
object o = ViewState["NavigateUrl"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["NavigateUrl"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the window or target frame that is
/// used to display the contents resulting from the hyperlink.
///
[
WebCategory("Behavior"),
DefaultValue(""),
TypeConverter(typeof(TargetConverter)),
WebSysDescription(SR.HyperLink_Target)
]
public virtual string Target {
get {
object o = ViewState["Target"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["Target"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the text to display for the hyperlink.
///
[
Localizable(true),
WebCategory("Appearance"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_Text)
]
public virtual string Text {
get {
object o = ViewState["Text"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["Text"] = value;
OnColumnChanged();
}
}
///
///
protected virtual string FormatDataNavigateUrlValue(object dataUrlValue) {
string formattedUrlValue = String.Empty;
if (!DataBinder.IsNull(dataUrlValue)) {
string formatting = DataNavigateUrlFormatString;
if (formatting.Length == 0) {
formattedUrlValue = dataUrlValue.ToString();
}
else {
formattedUrlValue = String.Format(CultureInfo.CurrentCulture, formatting, dataUrlValue);
}
}
return formattedUrlValue;
}
///
///
protected virtual string FormatDataTextValue(object dataTextValue) {
string formattedTextValue = String.Empty;
if (!DataBinder.IsNull(dataTextValue)) {
string formatting = DataTextFormatString;
if (formatting.Length == 0) {
formattedTextValue = dataTextValue.ToString();
}
else {
formattedTextValue = String.Format(CultureInfo.CurrentCulture, formatting, dataTextValue);
}
}
return formattedTextValue;
}
///
///
public override void Initialize() {
base.Initialize();
textFieldDesc = null;
urlFieldDesc = null;
}
///
///
/// Initializes the cell representing this column with the
/// contained hyperlink.
///
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) {
base.InitializeCell(cell, columnIndex, itemType);
if ((itemType != ListItemType.Header) &&
(itemType != ListItemType.Footer)) {
HyperLink hyperLink = new HyperLink();
hyperLink.Text = Text;
hyperLink.NavigateUrl = NavigateUrl;
hyperLink.Target = Target;
if ((DataNavigateUrlField.Length != 0) ||
(DataTextField.Length != 0)) {
hyperLink.DataBinding += new EventHandler(this.OnDataBindColumn);
}
cell.Controls.Add(hyperLink);
}
}
///
///
private void OnDataBindColumn(object sender, EventArgs e) {
Debug.Assert((DataTextField.Length != 0) || (DataNavigateUrlField.Length != 0),
"Shouldn't be DataBinding without a DataTextField and DataNavigateUrlField");
HyperLink boundControl = (HyperLink)sender;
DataGridItem item = (DataGridItem)boundControl.NamingContainer;
object dataItem = item.DataItem;
if ((textFieldDesc == null) && (urlFieldDesc == null)) {
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(dataItem);
string fieldName;
fieldName = DataTextField;
if (fieldName.Length != 0) {
textFieldDesc = props.Find(fieldName, true);
if ((textFieldDesc == null) && !DesignMode) {
throw new HttpException(SR.GetString(SR.Field_Not_Found, fieldName));
}
}
fieldName = DataNavigateUrlField;
if (fieldName.Length != 0) {
urlFieldDesc = props.Find(fieldName, true);
if ((urlFieldDesc == null) && !DesignMode) {
throw new HttpException(SR.GetString(SR.Field_Not_Found, fieldName));
}
}
}
if (textFieldDesc != null) {
object data = textFieldDesc.GetValue(dataItem);
string dataValue = FormatDataTextValue(data);
boundControl.Text = dataValue;
}
else if (DesignMode && (DataTextField.Length != 0)) {
boundControl.Text = SR.GetString(SR.Sample_Databound_Text);
}
if (urlFieldDesc != null) {
object data = urlFieldDesc.GetValue(dataItem);
string dataValue = FormatDataNavigateUrlValue(data);
boundControl.NavigateUrl = dataValue;
}
else if (DesignMode && (DataNavigateUrlField.Length != 0)) {
boundControl.NavigateUrl = "url";
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.Util;
///
/// Creates a column within the containing hyperlinks that
/// navigate to specified URLs.
///
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
public class HyperLinkColumn : DataGridColumn {
private PropertyDescriptor textFieldDesc;
private PropertyDescriptor urlFieldDesc;
///
/// Initializes a new instance of the class.
///
public HyperLinkColumn() {
}
///
/// Gets or sets the field in the DataSource that provides the URL of the page to navigate to.
///
[
WebCategory("Data"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_DataNavigateUrlField)
]
public virtual string DataNavigateUrlField {
get {
object o = ViewState["DataNavigateUrlField"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataNavigateUrlField"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the formatting applied to the
/// property.
///
[
WebCategory("Data"),
DefaultValue(""),
DescriptionAttribute("The formatting applied to the value bound to the NavigateUrl property.")
]
public virtual string DataNavigateUrlFormatString {
get {
object o = ViewState["DataNavigateUrlFormatString"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataNavigateUrlFormatString"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the field in the DataSource that will be used as the source of
/// data for the property.
///
[
WebCategory("Data"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_DataTextField)
]
public virtual string DataTextField {
get {
object o = ViewState["DataTextField"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataTextField"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the formatting applied to the
/// property.
///
[
WebCategory("Data"),
DefaultValue(""),
DescriptionAttribute("The formatting applied to the value bound to the Text property.")
]
public virtual string DataTextFormatString {
get {
object o = ViewState["DataTextFormatString"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["DataTextFormatString"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the URL to navigate to when the hyperlink is clicked.
///
[
WebCategory("Behavior"),
DefaultValue(""),
UrlProperty(),
WebSysDescription(SR.HyperLinkColumn_NavigateUrl)
]
public virtual string NavigateUrl {
get {
object o = ViewState["NavigateUrl"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["NavigateUrl"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the window or target frame that is
/// used to display the contents resulting from the hyperlink.
///
[
WebCategory("Behavior"),
DefaultValue(""),
TypeConverter(typeof(TargetConverter)),
WebSysDescription(SR.HyperLink_Target)
]
public virtual string Target {
get {
object o = ViewState["Target"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["Target"] = value;
OnColumnChanged();
}
}
///
/// Gets or sets the text to display for the hyperlink.
///
[
Localizable(true),
WebCategory("Appearance"),
DefaultValue(""),
WebSysDescription(SR.HyperLinkColumn_Text)
]
public virtual string Text {
get {
object o = ViewState["Text"];
if (o != null)
return(string)o;
return String.Empty;
}
set {
ViewState["Text"] = value;
OnColumnChanged();
}
}
///
///
protected virtual string FormatDataNavigateUrlValue(object dataUrlValue) {
string formattedUrlValue = String.Empty;
if (!DataBinder.IsNull(dataUrlValue)) {
string formatting = DataNavigateUrlFormatString;
if (formatting.Length == 0) {
formattedUrlValue = dataUrlValue.ToString();
}
else {
formattedUrlValue = String.Format(CultureInfo.CurrentCulture, formatting, dataUrlValue);
}
}
return formattedUrlValue;
}
///
///
protected virtual string FormatDataTextValue(object dataTextValue) {
string formattedTextValue = String.Empty;
if (!DataBinder.IsNull(dataTextValue)) {
string formatting = DataTextFormatString;
if (formatting.Length == 0) {
formattedTextValue = dataTextValue.ToString();
}
else {
formattedTextValue = String.Format(CultureInfo.CurrentCulture, formatting, dataTextValue);
}
}
return formattedTextValue;
}
///
///
public override void Initialize() {
base.Initialize();
textFieldDesc = null;
urlFieldDesc = null;
}
///
///
/// Initializes the cell representing this column with the
/// contained hyperlink.
///
public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) {
base.InitializeCell(cell, columnIndex, itemType);
if ((itemType != ListItemType.Header) &&
(itemType != ListItemType.Footer)) {
HyperLink hyperLink = new HyperLink();
hyperLink.Text = Text;
hyperLink.NavigateUrl = NavigateUrl;
hyperLink.Target = Target;
if ((DataNavigateUrlField.Length != 0) ||
(DataTextField.Length != 0)) {
hyperLink.DataBinding += new EventHandler(this.OnDataBindColumn);
}
cell.Controls.Add(hyperLink);
}
}
///
///
private void OnDataBindColumn(object sender, EventArgs e) {
Debug.Assert((DataTextField.Length != 0) || (DataNavigateUrlField.Length != 0),
"Shouldn't be DataBinding without a DataTextField and DataNavigateUrlField");
HyperLink boundControl = (HyperLink)sender;
DataGridItem item = (DataGridItem)boundControl.NamingContainer;
object dataItem = item.DataItem;
if ((textFieldDesc == null) && (urlFieldDesc == null)) {
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(dataItem);
string fieldName;
fieldName = DataTextField;
if (fieldName.Length != 0) {
textFieldDesc = props.Find(fieldName, true);
if ((textFieldDesc == null) && !DesignMode) {
throw new HttpException(SR.GetString(SR.Field_Not_Found, fieldName));
}
}
fieldName = DataNavigateUrlField;
if (fieldName.Length != 0) {
urlFieldDesc = props.Find(fieldName, true);
if ((urlFieldDesc == null) && !DesignMode) {
throw new HttpException(SR.GetString(SR.Field_Not_Found, fieldName));
}
}
}
if (textFieldDesc != null) {
object data = textFieldDesc.GetValue(dataItem);
string dataValue = FormatDataTextValue(data);
boundControl.Text = dataValue;
}
else if (DesignMode && (DataTextField.Length != 0)) {
boundControl.Text = SR.GetString(SR.Sample_Databound_Text);
}
if (urlFieldDesc != null) {
object data = urlFieldDesc.GetValue(dataItem);
string dataValue = FormatDataNavigateUrlValue(data);
boundControl.NavigateUrl = dataValue;
}
else if (DesignMode && (DataNavigateUrlField.Length != 0)) {
boundControl.NavigateUrl = "url";
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- XmlCharacterData.cs
- Panel.cs
- WindowsListViewScroll.cs
- AliasedSlot.cs
- HostingEnvironmentException.cs
- CompiledELinqQueryState.cs
- ThreadExceptionEvent.cs
- User.cs
- AsyncStreamReader.cs
- SafeHandles.cs
- FileChangesMonitor.cs
- OptionalMessageQuery.cs
- DataTableClearEvent.cs
- ProtocolsSection.cs
- MenuItemStyle.cs
- RemotingSurrogateSelector.cs
- CodeDirectoryCompiler.cs
- EncodedStreamFactory.cs
- DataRowExtensions.cs
- IdentityNotMappedException.cs
- TextSerializer.cs
- CheckBoxList.cs
- StackOverflowException.cs
- AutomationFocusChangedEventArgs.cs
- DbConnectionStringCommon.cs
- X509CertificateTrustedIssuerElement.cs
- ErrorTableItemStyle.cs
- Point3DAnimation.cs
- GC.cs
- RuleConditionDialog.Designer.cs
- DataGridTableStyleMappingNameEditor.cs
- TextPointerBase.cs
- BrushValueSerializer.cs
- TypeToken.cs
- ClientFormsAuthenticationCredentials.cs
- SignatureConfirmationElement.cs
- SqlNodeAnnotation.cs
- ActivityPreviewDesigner.cs
- DecoderBestFitFallback.cs
- DerivedKeyCachingSecurityTokenSerializer.cs
- XmlReflectionImporter.cs
- FileIOPermission.cs
- Pens.cs
- ServiceOperation.cs
- SafeRegistryHandle.cs
- TextServicesManager.cs
- Accessors.cs
- DbInsertCommandTree.cs
- WebHttpDispatchOperationSelector.cs
- ProcessHostMapPath.cs
- Line.cs
- DataFormats.cs
- contentDescriptor.cs
- HandlerFactoryCache.cs
- TemplateColumn.cs
- TargetControlTypeCache.cs
- DbFunctionCommandTree.cs
- CroppedBitmap.cs
- ACE.cs
- BCLDebug.cs
- EntityDataSourceEntitySetNameItem.cs
- AdornerHitTestResult.cs
- TdsParser.cs
- StatusBarAutomationPeer.cs
- ObjectIDGenerator.cs
- RulePatternOps.cs
- TemplateBamlTreeBuilder.cs
- NetNamedPipeSecurityElement.cs
- TextTreeInsertUndoUnit.cs
- TabControl.cs
- HtmlInputFile.cs
- TransactedReceiveData.cs
- HtmlHead.cs
- AnnotationResource.cs
- CurrentTimeZone.cs
- AuthenticatingEventArgs.cs
- SetterBaseCollection.cs
- XmlTextAttribute.cs
- DbMetaDataFactory.cs
- TemplateComponentConnector.cs
- FloatUtil.cs
- ListParagraph.cs
- ObjectDataSourceView.cs
- TransactionScope.cs
- AssemblyAttributes.cs
- WebEventCodes.cs
- PartialToken.cs
- ExpressionNormalizer.cs
- XmlDictionaryReaderQuotas.cs
- Parameter.cs
- EllipticalNodeOperations.cs
- TemplateColumn.cs
- MaterialGroup.cs
- EventDescriptor.cs
- DictionaryCustomTypeDescriptor.cs
- UdpTransportBindingElement.cs
- MinimizableAttributeTypeConverter.cs
- ControlCollection.cs
- SmtpSection.cs
- Stroke2.cs