ValidationDataType Enum
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Specifies the validation data types used by the CompareValidator and RangeValidator controls.
public enum class ValidationDataType
public enum ValidationDataType
type ValidationDataType =
Public Enum ValidationDataType
- Inheritance
Fields
Currency | 4 | A monetary data type. The value is treated as a Decimal. However, currency and grouping symbols are still allowed. |
Date | 3 | A date data type. Only numeric dates are allowed. The time portion cannot be specified. |
Double | 2 | A double precision floating point number data type. The value is treated as a Double. |
Integer | 1 | A 32-bit signed integer data type. The value is treated as a Int32. |
String | 0 | A string data type. The value is treated as a String. |
Examples
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>CompareValidator Example</title>
<script runat="server">
void Button_Click(Object sender, EventArgs e)
{
if (Page.IsValid)
{
lblOutput.Text = "Result: Valid!";
}
else
{
lblOutput.Text = "Result: Not valid!";
}
}
void Operator_Index_Changed(Object sender, EventArgs e)
{
Compare1.Operator = (ValidationCompareOperator) ListOperator.SelectedIndex;
Compare1.Validate();
}
void Type_Index_Changed(Object sender, EventArgs e)
{
Compare1.Type = (ValidationDataType) ListType.SelectedIndex;
Compare1.Validate();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>CompareValidator Example</h3>
<br />
Enter a value in each textbox. Select a comparison operator<br />
and data type. Click "Validate" to compare values.
<table style="background-color:#eeeeee; padding:10">
<tr valign="top">
<td>
<h5>String 1:</h5>
<asp:TextBox id="TextBox1"
runat="server"/>
</td>
<td>
<h5>Comparison Operator:</h5>
<asp:ListBox id="ListOperator"
OnSelectedIndexChanged="Operator_Index_Changed"
runat="server">
<asp:ListItem Selected="True" Value="Equal">Equal</asp:ListItem>
<asp:ListItem Value="NotEqual">NotEqual</asp:ListItem>
<asp:ListItem Value="GreaterThan">GreaterThan</asp:ListItem>
<asp:ListItem Value="GreaterThanEqual">GreaterThanEqual</asp:ListItem>
<asp:ListItem Value="LessThan">LessThan</asp:ListItem>
<asp:ListItem Value="LessThanEqual">LessThanEqual</asp:ListItem>
<asp:ListItem Value="DataTypeCheck">DataTypeCheck</asp:ListItem>
</asp:ListBox>
</td>
<td>
<h5>String 2:</h5>
<asp:TextBox id="TextBox2"
runat="server"/>
<br />
<asp:Button id="Button1"
Text="Validate"
OnClick="Button_Click"
runat="server"/>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<h5>Data Type:</h5>
<asp:ListBox id="ListType"
OnSelectedIndexChanged="Type_Index_Changed"
runat="server">
<asp:ListItem Selected="true" Value="String" >String</asp:ListItem>
<asp:ListItem Value="Integer" >Integer</asp:ListItem>
<asp:ListItem Value="Double" >Double</asp:ListItem>
<asp:ListItem Value="Date" >Date</asp:ListItem>
<asp:ListItem Value="Currency" >Currency</asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
<asp:CompareValidator id="Compare1"
ControlToValidate="TextBox1"
ControlToCompare="TextBox2"
EnableClientScript="False"
Type="String"
runat="server"/>
<br />
<asp:Label id="lblOutput"
Font-Names="verdana"
Font-Size="10pt"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>CompareValidator Example</title>
<script runat="server">
Sub Button_Click(sender As Object, e As EventArgs)
If Page.IsValid Then
lblOutput.Text = "Result: Valid!"
Else
lblOutput.Text = "Result: Not valid!"
End If
End Sub
Sub Operator_Index_Changed(sender As Object, e As EventArgs)
Compare1.Operator = CType(ListOperator.SelectedIndex, ValidationCompareOperator)
Compare1.Validate()
End Sub
Sub Type_Index_Changed(sender As Object, e As EventArgs)
Compare1.Type = CType(ListType.SelectedIndex, ValidationDataType)
Compare1.Validate()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>CompareValidator Example</h3>
<br />
Enter a value in each textbox. Select a comparison operator<br />
and data type. Click "Validate" to compare values.
<table style="background-color:#eeeeee; padding:10">
<tr valign="top">
<td>
<h5>String 1:</h5>
<asp:TextBox id="TextBox1"
runat="server"/>
</td>
<td>
<h5>Comparison Operator:</h5>
<asp:ListBox id="ListOperator"
OnSelectedIndexChanged="Operator_Index_Changed"
runat="server">
<asp:ListItem Selected="True" Value="Equal">Equal</asp:ListItem>
<asp:ListItem Value="NotEqual">NotEqual</asp:ListItem>
<asp:ListItem Value="GreaterThan">GreaterThan</asp:ListItem>
<asp:ListItem Value="GreaterThanEqual">GreaterThanEqual</asp:ListItem>
<asp:ListItem Value="LessThan">LessThan</asp:ListItem>
<asp:ListItem Value="LessThanEqual">LessThanEqual</asp:ListItem>
<asp:ListItem Value="DataTypeCheck">DataTypeCheck</asp:ListItem>
</asp:ListBox>
</td>
<td>
<h5>String 2:</h5>
<asp:TextBox id="TextBox2"
runat="server"/>
<br />
<asp:Button id="Button1"
Text="Validate"
OnClick="Button_Click"
runat="server"/>
</td>
</tr>
<tr>
<td colspan="3" align="center">
<h5>Data Type:</h5>
<asp:ListBox id="ListType"
OnSelectedIndexChanged="Type_Index_Changed"
runat="server">
<asp:ListItem Selected="true" Value="String" >String</asp:ListItem>
<asp:ListItem Value="Integer" >Integer</asp:ListItem>
<asp:ListItem Value="Double" >Double</asp:ListItem>
<asp:ListItem Value="Date" >Date</asp:ListItem>
<asp:ListItem Value="Currency" >Currency</asp:ListItem>
</asp:ListBox>
</td>
</tr>
</table>
<asp:CompareValidator id="Compare1"
ControlToValidate="TextBox1"
ControlToCompare="TextBox2"
EnableClientScript="False"
Type="String"
runat="server"/>
<br />
<asp:Label id="lblOutput"
Font-Names="verdana"
Font-Size="10pt"
runat="server"/>
</form>
</body>
</html>
Remarks
The ValidationDataType enumeration represents the different data types that the CompareValidator and RangeValidator controls can validate. When you specify a data type for validation control and the input control being validated passes validation, the value of the input control can be parsed to the specified data type.
Applies to
See also
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기