The following example shows a custom field template that checks the quantity of product ordered. If the quantity ordered is greater than the maximum number allowed, the field template displays the value by using red foreground.
<%@ Control Language="vb" CodeFile="MyCustom.ascx.vb" Inherits="DynamicData_FieldTemplates_MyCustom" %>
<asp:Label id="Label1" runat="server" Text='<%# FieldValueString %>'></asp:Label>
<%@ Control Language="C#" CodeFile="MyCustom.ascx.cs" Inherits="DynamicData_FieldTemplates_MyCustom" %>
<asp:Label id="Label1" runat="server" Text='<%# FieldValueString %>'></asp:Label>
Public Partial Class DynamicData_FieldTemplates_MyCustom
Inherits System.Web.DynamicData.FieldTemplateUserControl
Public Overloads Overrides ReadOnly Property DataControl() As Control
Get
Return Label1
End Get
End Property
Protected Overloads Overrides Sub OnDataBinding(ByVal e As EventArgs)
Dim MaxQuantity As Integer = 10
'Get the current number of items ordered
Dim currentValue As Short = CShort(FieldValue)
' Compare the number ordered to the maximun quantity allowed and set the backgroud if the number ordered exceeds the max number allowed.
If currentValue > MaxQuantity Then
Label1.ForeColor = System.Drawing.Color.Red
End If
End Sub
End Class
public partial class DynamicData_FieldTemplates_MyCustom : System.Web.DynamicData.FieldTemplateUserControl
{
public override Control DataControl {
get {
return Label1;
}
}
protected override void OnDataBinding(EventArgs e)
{
int MaxQuantity = 10;
//Get the current number of items ordered
short currentValue = (short)FieldValue;
// Compare the number ordered to the maximun quantity allowed and set the backgroud if the number ordered exceeds the max number allowed.
if (currentValue > MaxQuantity)
{
Label1.ForeColor = System.Drawing.Color.Red;
}
}
}
<MetadataType(GetType(SalesOrderDetailMetadata))> _
Public Partial Class SalesOrderDetail
End Class
Public Class SalesOrderDetailMetadata
<UIHint("MyCustom")> _
Public OrderQty As Object
End Class
[MetadataType(typeof(SalesOrderDetailMetadata))]
public partial class SalesOrderDetail
{
}
public class SalesOrderDetailMetadata
{
[UIHint("MyCustom")]
public Object OrderQty;
}