Databases Reference
In-Depth Information
LISTING 1.8
Integer_Edit Field Template (Code-behind)
using System;
using System.Collections.Specialized;
using System.Web.DynamicData;
using System.Web.UI;
namespace WebApplication.DynamicData.FieldTemplates
{
public partial class Integer_EditField : FieldTemplateUserControl
{
public override Control DataControl
{
get { return this.textBox; }
}
protected void Page_Load(object sender, EventArgs e)
{
this.textBox.ToolTip = this.Column.Description;
this.SetUpValidator(this.requiredFieldValidator);
this.SetUpValidator(this.compareValidator);
this.SetUpValidator(this.regularExpressionValidator);
this.SetUpValidator(this.rangeValidator);
this.SetUpValidator(this.dynamicValidator);
}
protected override void ExtractValues(IOrderedDictionary dictionary)
{
dictionary[this.Column.Name] = this.ConvertEditedValue(this.textBox.Text);
}
}
}
Field templates are incredibly flexible. This particular template, Integer_Edit , can be
reused for other integer columns in the Product table, such as UnitsOnOrder and
ReorderLevel, as well as integer columns in all other tables in the data model. The field
template will even configure the RangeValidator based on the range of values appropriate
for a data type of the particular column, such as Int16 or Int32 . All you need to do is
place a DynamicControl on your page and specify its DataField and Mode properties.
 
Search WWH ::




Custom Search