📄 validateddetailsview.aspx
字号:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ValidatedDetailsView.aspx.vb" Inherits="ValidatedDetailsView_aspx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
Sub ItemUpdated(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs)
If e.Exception Is Nothing Then
txtError.Visible = False
Else
txtError.Visible = True
txtError.Text = "Error: " + Mid(e.Exception.Message, 1, e.Exception.Message.IndexOf("."))
e.ExceptionHandled = True
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Validated GridView and DetailsView Controls</title>
<script language="vbscript">
Function ValidateProductID(source, args)
args.IsValid = True
Prefix = "gvOrderDetails_ctl"
Suffix = "_lblProductID"
LastRow = 99
For Ctr = 1 To 99
If Ctr < 10 Then
CtlNum = "0" & Ctr
Else
CtlNum = Ctr
End If
CtlName = Prefix & CtlNum & Suffix
Set objCtl = Document.getElementById(CtlName)
If objCtl Is Nothing Then
If Ctr > LastRow Then
'Last valid row
Exit For
End If
Else
ProductID = objCtl.innerText
LastRow = Ctr
If ProductID = args.Value Then
args.IsValid = False
Exit For
End If
End If
Next
End Function
</script>
</head>
<body style="font-size: 12pt" bgcolor="#ffffff">
<form id="frmDetails" runat="server">
<div style="background-color: Gainsboro">
<div style="text-align: left">
<span style="font-size: 14pt; font-family: Arial; height: 25px ; width: 406px;"><b> Validated DetailsView and Linked GridView</b></span>
<asp:LinkButton ID="lbEditable" Font-Names="Arial" Font-Size="11pt" Runat="server"
PostBackUrl="~/ValidatedGridView.aspx" ToolTip="Click to display validated, editable GridView page"
Font-Bold="True">Validated GridView</asp:LinkButton> <asp:TextBox
ID="txtError" Runat="server" Height="18px" Width="718px" ForeColor="Red" Visible="False"></asp:TextBox>
<table style="width: 718px; height: 25px">
<tr>
<td valign="top" style="width: 347px; height: 21px">
<asp:DetailsView ID="dvOrders" Runat="server" Font-Size="10pt" DataKeyNames="OrderID"
DataSourceID="dsNWOrdersDetails" AutoGenerateRows="False" Font-Names="Verdana" AllowPaging="True" Width="335px" Height="313px" EmptyDataText="Missing" OnItemUpdated="ItemUpdated">
<PagerSettings NextPageText="Next" FirstPageText="First" LastPageText="Last" PreviousPageText="Previous"
Mode="NextPreviousFirstLast"></PagerSettings>
<Fields>
<asp:BoundField ReadOnly="True" HeaderText="Order ID" InsertVisible="False" DataField="OrderID"
SortExpression="OrderID"></asp:BoundField>
<asp:TemplateField SortExpression="CustomerID" HeaderText="Customer ID"><EditItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("CustomerID") %>' ID="txtEditCustomerID" Width="50px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEditCustomerID" Runat="server" ErrorMessage="CustomerID is required."
ControlToValidate="txtEditCustomerID" Display="Dynamic">
Required Field</asp:RequiredFieldValidator> <asp:RegularExpressionValidator
ID="revEditCustomerID" Runat="server" ToolTip="CustomerID must be five capital letters."
Display="Dynamic" ControlToValidate="txtEditCustomerID" ErrorMessage="CustomerID must be five capital letters."
ValidationExpression="[A-Z]{5}">
Format: ABCDE</asp:RegularExpressionValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("CustomerID") %>' ID="lblEditCustomerID"></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtInsertCustomerID" Runat="server" Width="50px" Text='<%# Bind("CustomerID") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertCustomerID" Runat="server" ErrorMessage="CustomerID is required."
ControlToValidate="txtInsertCustomerID" Display="Dynamic">
Required Field</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revInsertCustomerID" Runat="server" ToolTip="CustomerID must be five capital letters."
Display="Dynamic" ControlToValidate="txtInsertCustomerID" ErrorMessage="CustomerID must be five capital letters."
ValidationExpression="[A-Z]{5}">Format: ABCDE</asp:RegularExpressionValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="EmployeeID" HeaderText="Employee ID"><EditItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("EmployeeID") %>' ID="txtEditEmployeeID" Width="25px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEditEmployeeID" Runat="server" ToolTip="EmployeeID is required and must be between 1 and 9"
ErrorMessage="EmployeeID is required." ControlToValidate="txtEditEmployeeID" Display="Dynamic">
Required Field</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvEditEmployeeID" Runat="server" ToolTip="EmployeeID must be 1 to 9."
Display="Dynamic" ControlToValidate="txtEditEmployeeID" ErrorMessage="EmployeeID must be 1 to 9."
MaximumValue="9" MinimumValue="1" Type="Integer">
1 to 9 is Valid</asp:RangeValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("EmployeeID") %>' ID="lblInsertEmployeeID"></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("EmployeeID") %>' ID="txtInsertEmployeeID" Width="25px" ></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertEmployeeID" Runat="server" ToolTip="Employee ID is required and must be between 1 and 9"
ErrorMessage="Employee ID is required." ControlToValidate="txtInsertEmployeeID">
Required Field</asp:RequiredFieldValidator>
<asp:RangeValidator ID="rvInsertEmployeeID" Runat="server" ToolTip="EmployeeID must be 1 to 9."
Display="Dynamic" ControlToValidate="txtInsertEmployeeID" ErrorMessage="EmployeeID must be 1 to 9."
MaximumValue="9" MinimumValue="1" Type="Integer">
1 to 9 is Valid</asp:RangeValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="OrderDate" HeaderText="Order Date"><EditItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' ID="txtEditOrderDate" Width="80px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEditOrderDate" Runat="server" ErrorMessage="OrderDate is required."
ControlToValidate="txtEditOrderDate" Display="Dynamic">
Required Field</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' ID="lblEditOrderDate"></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("OrderDate", "{0:d}") %>' ID="txtInsertOrderDate" Width="80px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertOrderDate" Runat="server" ErrorMessage="OrderDate is required."
ControlToValidate="txtInsertOrderDate" Display="Dynamic">
Required Field</asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="RequiredDate" HeaderText="Required Date"><EditItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("RequiredDate", "{0:d}") %>' ID="txtEditRequiredDate" Width="80px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEditRequiredDate" Runat="server" ToolTip="RequiredDate is required."
Display="Dynamic" ControlToValidate="txtEditRequiredDate" ErrorMessage="RequiredDate is required.">
Required Field</asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("RequiredDate", "{0:d}") %>' ID="lblEditRequiredDate"></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("RequiredDate", "{0:d}") %>' ID="txtInsertRequiredDate" Width="80px"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvInsertRequiredDate" Runat="server" ToolTip="RequiredDate is required."
Display="Dynamic" ControlToValidate="txtInsertRequiredDate" ErrorMessage="RequiredDate is required.">
Required Field</asp:RequiredFieldValidator>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="ShippedDate" HeaderText="Shipped Date"><EditItemTemplate>
<asp:TextBox Runat="server" Text='<%# Bind("ShippedDate", "{0:d}") %>' ID="txtEditShippedDate" Width="80px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label Runat="server" Text='<%# Bind("ShippedDate", "{0:d}") %>' ID="lblEditShippedDate"></asp:Label>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -