RangeValidator只能用来比较两个控件的值,如果要让一个时间在两个时间之间,就必须用两个RangeValidator控件。
解决方案 »
- 请问关于\u开头的汉字编码是什么类型的编码,c#怎样转换
- GridView,一个单元格显示和别的单元格不一样的颜色
- 【求一高效算法,感兴趣的朋友可以来试试,高分】
- 上传htm文件时,怎样将htm中的图片一起上传?
- asp.net页面排版问题
- 急救——Visual Studio.net检测到指定的web服务器运行的不是asp.net1.1版……
- datagrid一个模板列绑定多个值,如何取得每一个值在后台代码中!
- 关于如何把TEXTBOX写入的日期型写入到数据库的方法!新人求前辈指导。
- 求ASP.NET调用数据库中的存储过程,返回一个DataSet、Output、Value的类
- 请问:如何让ToolBar控件中的某一项(Button、Label......)隐藏掉?
- DataGrid 控件绑定问题,多谢!
- 我将一个datagrid绑定到一个表(在程序中dataview实现),怎么让它隐藏关键字段的显示,而且能在删除记录的时候取到这个ID号。。谢谢
用DateTime.Parse(TextBox1.Text)
通过设定max和MinimumValue的值,
并把type属性设为Date,
maximumvalue=DateTime.Parse(endtime.Text)
minimumvalue=DateTime.Parse(starttime.Text)
我觉得这是完全可以实现的
Sub Button1_Click(Sender as Object,e as eventArgs)
Range1.MinimumValue=DateTime.Parse(startime.Text)
Range1.MaximumValue=DateTime.Parse(endtime.Text)
'进行验证
Range1.Validate()
If Page.IsValid then
'通过验证所要执行的程序写在这
End If
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>使用RangeValidator控件</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
起始时间:<asp:TextBox ID="startime" Runat="server" />
<p></p>
截止时间:<asp:TextBox ID="endtime" Runat="server" />
<p></p>
提交时间:<asp:TextBox ID="midtime" Runat="server" />
<p></p>
<asp:RangeValidator ID="Range1" Runat="server" ControlToValidate="midtime" Type="Date">
提交时间必须在起始时间和截止时间之间
</asp:RangeValidator>
<asp:Button ID="Button1" Text="输入" Runat="server" OnClick="Button1_Click" /><p></p>
</form>
</body>
</html>
属性是string类型的,所以只要
Range1.MinimumValue=startime.Text
就可以了
记得指定type为date
<script language="vb" runat="server">
Sub Button1_Click(Sender as Object,e as eventArgs)
Range1.MinimumValue=startime.Text
Range1.MaximumValue=endtime.Text
'进行验证
Range1.Validate()
If Page.IsValid then
'通过验证所要执行的程序写在这
End If
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>使用RangeValidator控件</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
起始时间:<asp:TextBox ID="startime" Runat="server" />
<p></p>
截止时间:<asp:TextBox ID="endtime" Runat="server" />
<p></p>
提交时间:<asp:TextBox ID="midtime" Runat="server" />
<p></p>
<asp:RangeValidator ID="Range1" Runat="server" ControlToValidate="midtime" Type="Date">
提交时间必须在起始时间和截止时间之间
</asp:RangeValidator>
<asp:Button ID="Button1" Text="输入" Runat="server" OnClick="Button1_Click" /><p></p>
</form>
</body>
</html>
去掉Type="Date"Sub Button1_Click(Sender as Object,e as eventArgs)
Range1.MinimumValue=startime.Text
Range1.MaximumValue=endtime.Text
Range1.Type=ValidationDataType.Date
'进行验证
MinimumValue="1999-01-01";
MaximumValue="2099-01-01";
Program Passed!