|
源代码网推荐源代码网整理以下ASP.NET在设计时和VB一样,提供了种类丰富的控件。在这里主要介绍六种验证控件,和DATAGRID控件,验证控件用以实现对表单输入的方便的验证,DATAGRID用以从指定数据源绑定数据,加以显示或者更新。
源代码网整理以下一、验证控件
源代码网整理以下验证控件有以下几种:
源代码网整理以下RequiredFieldValidator,必须填内容
源代码网整理以下CompareValidator,同某个常量或另外的控件的值做比较
源代码网整理以下RangeValidator,范围验证
源代码网整理以下RegularExpressionValidator,同一个模式做比较,用于EMAIL,邮政编码等验证
源代码网整理以下CustomValidator,自定义条件验证
源代码网整理以下ValidationSummary,显示验证后的错误信息摘要,如验证失败,则Page对象IsValid属性被设为False,同时,自动显示出错误信息。
源代码网整理以下验证控件的作用是自动产生客户端验证脚本,否则,在提交回服务器后在服务器端进行验证。验证控件只对部分控件的特定属性有效:
源代码网整理以下
以下为引用的内容:
源代码网整理以下HtmlInputText value HtmlTextArea value HtmlSelect value HtmlInputFile value TextBox Text ListBox SelectedItem DropDownList SelectedItem RadioButtonList SelectedItem RequiredFieldValidator
源代码网整理以下CompareValidator
|
源代码网整理以下属性:
源代码网整理以下
以下为引用的内容: ControlToValidate 验证的控件 ControlToCompare 比较的值 Operator 比较方法 |
源代码网整理以下例:
源代码网整理以下
以下为引用的内容: <asp: CompareValidator id="Compare" runat="Server" ControlToValidate="Password " ControlToCompare ="Confirmpwd " Operator ="equal" > </asp: CompareValidator> 。RangeValidator |
源代码网整理以下属性:
源代码网整理以下
以下为引用的内容: ControlToValidate 验证的控件 MiniumControl 最小值 MaxiumControl 最大值 |
源代码网整理以下例:
源代码网整理以下
以下为引用的内容:
源代码网整理以下<asp: RangeValidator id="Range " runat="Server" ControlToValidate="Age" MiniumControl = 15 MaxiumControl = 100 > </asp: RangeValidator>
源代码网整理以下RegularExpressionValidator
|
源代码网整理以下属性:
源代码网整理以下
以下为引用的内容: ControlToValidate 验证的控件 ValidationExpression 匹配模式,用正则表达式(一个连接) |
源代码网整理以下例:
源代码网整理以下
以下为引用的内容: <asp:RegularExpressionValidator id="Regular1" runat="Server" ControlToValidate="TextBox1" ValidationExpression="^d{5}$" Display="static" Font-Size="10pt"> |
源代码网整理以下邮政编码必须是5个数字
源代码网整理以下</asp:RegularExpressionValidator>
源代码网整理以下CustomValidator
源代码网整理以下属性:
源代码网整理以下
以下为引用的内容: ControlToValidate 验证的控件 OnServerValidationFunction 服务器端验证函数名称 ClientValidationFunction 客户端验证函数名称 |
源代码网整理以下例:
源代码网整理以下
以下为引用的内容: <script language="c#" runat="server"> bool ServerValidate(Object source,String value){ ... } </script> <asp:CustomValidator id="CustomValidate" runat="Server" ControlToValidate="Text1" OnServerValidationFunction="ServerValidate" ClientValidationFunction="ClientValidate"> 不是一个偶数哦! </asp:CustomValidator> <Script language="javascript"> function ClientValidate(source,value) { …… } </Script> |
源代码网整理以下(连接到一个完整的验证程序页面)更多内容可参看:
源代码网整理以下EMAIL地址验证程序
源代码网整理以下ASP.NET验证控件
源代码网整理以下二、DATAGRID
源代码网整理以下下面是用DATAGRID 显示一个数据表的代码
源代码网整理以下
以下为引用的内容:
源代码网整理以下<%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.ADO" %>
源代码网整理以下<script language="VB" runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) Dim conn As ADOConnection Dim dtCmd As ADODataSetCommand Dim ds As DataSet Dim str_sql As String dim str_conn As String str_sql = "select * from test" str_conn = "DBQ="&Server.MapPath("test.mdb") &";Driver={Microsoft Access Driver (*.mdb)};" connobj = New ADOConnection(str_conn) dtsCmdobj = New ADODataSetCommand(str_sql, connobj) dtSobj = New DataSet() dtsCmdobj.FillDataSet(dtsobj, "test") dtgrid.DataSource = dtsobj.Tables("test").DefaultView dtgrid.DataBind() End Sub </script> <html> <body> <asp:DataGrid id="dtgrid" HeaderStyle-Font-Bold="True" ToolTip="data Grid provided with asp+" runat="server" maintainviewstate="false" /> </body> </html>
|
源代码网供稿. |