⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 validatedgridview.aspx

📁 wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重推荐,电子书,电子书下载
💻 ASPX
📖 第 1 页 / 共 2 页
字号:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ValidatedGridView.aspx.vb" Inherits="ValidatedGridView_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Validated GridView and DetailsView Controls</title>
    <script language="vbscript">
      Function ValidateFreight(source, args)
         'Test for Freight value < $5.00 if order has shipped
			If args.Value < 5 Then
				FreightID = Document.activeElement.id
				'Format: gvOrdersEditable_ctl##_txtFreight (## is a sequential number)
				ShipDateID = Left(FreightID, InStrRev(FreightID, "_")) & "txtShippedDate"
				ShipDate = Document.getElementById(ShipDateID).outerHTML
				ShipDate = Mid(ShipDate, Instr(ShipDate, "value=") + 6)
				ShipDate = Left(ShipDate, Instr(ShipDate, " name=") -1)
				If Len(ShipDate) > 4 Then
					args.IsValid = False					
				Else
					args.IsValid = True
				End If					
			End If
		End Function
	 </script>
</head>
<body style="font-size: 12pt">
    <form id="frmValidated" runat="server">
    <div style="background-color: Gainsboro">
		 <div style="text-align: left">
			 <div style="text-align: left">
			 <span style="font-size: 14pt; font-family: Arial"><b>&nbsp;Validated GridView Control&nbsp;&nbsp;&nbsp;&nbsp;<asp:LinkButton ID="lbDetailsView" PostBackUrl="~/ValidatedDetailsView.aspx"
				 Font-Size="11pt" Runat="server" ToolTip="Click to view validated, editable DetailsViews and GridView ">Validated DetailsViews</asp:LinkButton>&nbsp;&nbsp;
			 &nbsp;<asp:Label ID="lblLink" Runat="server" Font-Size="10pt" Font-Names="Verdana"
				 Font-Bold="False" Text="PostBacks:"></asp:Label>
			 <asp:TextBox ID="txtPostBacks" Runat="server" Width="32px">0</asp:TextBox>
			 <asp:TextBox ID="txtError" Runat="server" Font-Size="10pt" ForeColor="Red" Font-Names="Verdana"
				 Width="772px" Height="18px" Visible="False"></asp:TextBox>
			 <br />
			 <asp:ValidationSummary ID="vsOrderData" Runat="server" Font-Size="10pt" Font-Bold="False"
				 Font-Names="Verdana" DisplayMode="SingleParagraph" ShowMessageBox="True" Width="772px" Height="18px" BorderColor="DimGray" BorderStyle="Solid" BackColor="White" BorderWidth="1px" HeaderText="Validation summary:" ToolTip="This is a summary of all order data validation errors." />
			 </b></span></div>
			 <table style="width: 800px; height: 419px" cellpadding="2" border="0">
				 <tr>
					 <td style=" height: 209px; background-color: gainsboro; width: 695px;" colspan="2">
						 <asp:GridView ID="gvOrdersEditable" Style="font-size: 10pt; font-family: Verdana" Runat="server"
							 DataSourceID="dsOrdersEdit" DataKeyNames="OrderID" AutoGenerateColumns="False" AllowPaging="True"
							 BorderWidth="1px" BackColor="White" GridLines="Vertical" CellPadding="3" BorderStyle="None"
							 BorderColor="#999999" PageSize="15" AutoGenerateEditButton="True">
							 <FooterStyle ForeColor="Black" BackColor="Gainsboro"></FooterStyle>
							 <PagerStyle ForeColor="Black" HorizontalAlign="Left" BackColor="Gainsboro" Font-Names="Arial" Font-Size="11pt" Font-Bold="True"></PagerStyle>
							 <HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#000084"></HeaderStyle>
							 <PagerSettings FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast"></PagerSettings>
							 <AlternatingRowStyle BackColor="Gainsboro"></AlternatingRowStyle>
							 <Columns>
								 <asp:BoundField ReadOnly="True" HeaderText="Order ID" InsertVisible="False" DataField="OrderID"
									 SortExpression="OrderID">
									 <ItemStyle HorizontalAlign="Right" VerticalAlign="Middle"></ItemStyle>
								 </asp:BoundField>
								 <asp:TemplateField SortExpression="CustomerID" HeaderText="Cust. ID"><EditItemTemplate>
										<asp:TextBox ID="txtCustomerID" Runat="server" Width="52px" Text='<%# Bind("CustomerID") %>'></asp:TextBox>
										<asp:RequiredFieldValidator ID="rfvCustomerID" Runat="server" ErrorMessage="CustomerID is required."
										 Display="Dynamic" ControlToValidate="txtCustomerID" ToolTip="CustomerID is a required field.">Required!</asp:RequiredFieldValidator>
										 <asp:RegularExpressionValidator ID="revCustomerID" Runat="server" ErrorMessage="CustomerID must be 5 capital letters."
										 Display="Dynamic" ControlToValidate="txtCustomerID" ValidationExpression="[A-Z]{5}" ToolTip="CustomerID must be 5 capital letters.">[ABCDE]</asp:RegularExpressionValidator></EditItemTemplate>
									 <ItemStyle HorizontalAlign="Left" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("CustomerID") %>' ID="lblCustomerID"></asp:Label>
									 </ItemTemplate>
								 </asp:TemplateField>
								 <asp:TemplateField HeaderText="Empl. ID"><EditItemTemplate>
									 <asp:DropDownList ID="ddlEmployee" Runat="server" Height="22px" Width="94px" DataSourceID="dsEmployees"
										 DataValueField="EmployeeID" DataTextField="LastName" SelectedValue='<%# Bind("EmployeeID") %>'>
									 </asp:DropDownList><br />
									 <asp:RangeValidator ID="rvEmployeeID" Runat="server" ErrorMessage="Valid EmployeeID valus are 1 to 9."
										 Display="Dynamic" ControlToValidate="ddlEmployee" Type="Integer" MaximumValue="9"
										 MinimumValue="1">1 to 9 Required!</asp:RangeValidator></EditItemTemplate>
									 <ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("EmployeeID") %>' ID="lblEmployeeID"></asp:Label>
									 </ItemTemplate>
								 </asp:TemplateField>
								 <asp:TemplateField SortExpression="OrderDate" HeaderText="Order Date"><EditItemTemplate>
									 <asp:TextBox ID="txtOrderDate" Runat="server" Width="76px" Text='<%# Bind("OrderDate", "{0:d}") %>'></asp:TextBox>
										<asp:RequiredFieldValidator ID="rfvOrderDate" Runat="server" ControlToValidate="txtOrderDate" 
										ErrorMessage="OrderDate is required." Display="Dynamic" ToolTip="OrderDate is a required field.">Required!</asp:RequiredFieldValidator>
										<asp:RangeValidator ID="rvOrderDate" Runat="server" ToolTip="Dates must be in ShortDate format (MM/DD/YYYY)"
										 ControlToValidate="txtOrderDate" ErrorMessage="Dates must be in M/D/YYYY format."
										 MinimumValue="1/1/1980" MaximumValue="12/31/2099" Type="Date" Display="Dynamic">[M/D/YYYY]</asp:RangeValidator>
										 <asp:RegularExpressionValidator ID="revOrderDate" Runat="server"
										 ToolTip="Date format must be M/D/YYYY and date must be valid." Display="Dynamic"
										 ErrorMessage="Date format must be M/D/YYYY." ControlToValidate="txtOrderDate"
										 ValidationExpression="^((((0?[13578])|(1[02]))[\/]?((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))[\/]?((0?[1-9]|[0-2][0-9])|(30)))|(0?[2][\/]?(0?[1-9]|[0-2][0-9])))[\/]?\d{4}$">[M/D/YYYY]</asp:RegularExpressionValidator></EditItemTemplate>
									 <ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' ID="lblOrderDate"></asp:Label>
									 </ItemTemplate>
								 </asp:TemplateField>
								 <asp:TemplateField SortExpression="RequiredDate" HeaderText="Required Date"><EditItemTemplate>
									<asp:TextBox ID="txtRequiredDate" Runat="server" Width="76px" Text='<%# Bind("RequiredDate", "{0:d}") %>'></asp:TextBox>
									 <asp:RequiredFieldValidator ID="rfvRequiredDate" Runat="server" ToolTip="RequiredDate is required and must be later than OrderDate."
										 Display="Dynamic" ErrorMessage="RequiredDate is required." ControlToValidate="txtRequiredDate">
										 Required!</asp:RequiredFieldValidator>
									 <asp:CompareValidator ID="cvRequiredDate" Runat="server" ToolTip="RequiredDate must be later than OrderDate."
										 Display="Dynamic" ErrorMessage="RequiredDate must be later than OrderDate." ControlToValidate="txtRequiredDate"
										 Operator="GreaterThan" ControlToCompare="txtOrderDate">
										 Impossible!</asp:CompareValidator>&nbsp;<asp:RegularExpressionValidator ID="revRequiredDate" Runat="server" ToolTip="Date format must be M/D/YYYY and date must be valid."
										 Display="Dynamic" ErrorMessage="Date format must be M/D/YYYY." ControlToValidate="txtRequiredDate"
										 ValidationExpression="^((((0?[13578])|(1[02]))[\/]?((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))[\/]?((0?[1-9]|[0-2][0-9])|(30)))|(0?[2][\/]?(0?[1-9]|[0-2][0-9])))[\/]?\d{4}$">
											 [M/D/YYYY]</asp:RegularExpressionValidator>
									 </EditItemTemplate>
									 <ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("RequiredDate", "{0:d}") %>' ID="lblRequiredDate"></asp:Label>
									 </ItemTemplate>
								 </asp:TemplateField>
								 <asp:TemplateField SortExpression="ShippedDate" HeaderText="Shipped Date"><EditItemTemplate>
									 <asp:TextBox ID="txtShippedDate" Runat="server" Text='<%# Bind("ShippedDate", "{0:d}") %>'
										 Width="76px"></asp:TextBox>
									 <asp:RegularExpressionValidator ID="revShippedDate" Runat="server" ToolTip="Date format must be M/D/YYYY and date must be valid."
										 Display="Dynamic" ErrorMessage="Date format must be M/D/YYYY." ControlToValidate="txtShippedDate"
										 ValidationExpression="^((((0?[13578])|(1[02]))[\/]?((0?[1-9]|[0-2][0-9])|(3[01])))|(((0?[469])|(11))[\/]?((0?[1-9]|[0-2][0-9])|(30)))|(0?[2][\/]?(0?[1-9]|[0-2][0-9])))[\/]?\d{4}$">[M/D/YYYY]</asp:RegularExpressionValidator>
								 </EditItemTemplate>
									 <ItemStyle HorizontalAlign="Right" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("ShippedDate", "{0:d}") %>' ID="lblShippedDate"></asp:Label>
									 </ItemTemplate>
								 </asp:TemplateField>
								 <asp:TemplateField SortExpression="ShipVia" HeaderText="Ship Via"><EditItemTemplate>
									 <asp:DropDownList ID="ddlShipper" Runat="server" Height="22px" Width="124px" DataSourceID="dsShippers"
										 DataValueField="ShipperID" DataTextField="CompanyName" SelectedValue='<%# Bind("ShipVia") %>'>
									 </asp:DropDownList>
								 </EditItemTemplate>
									 <ItemStyle HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
									 <ItemTemplate>
										 <asp:Label Runat="server" Text='<%# Bind("ShipVia") %>' ID="lblShipVia"></asp:Label>
									 </ItemTemplate>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -