<%@ Page Language="C#" %> <%@ Import Namespace="System.Data.SqlClient" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server"> protected void srcProducts_Updating(object sender, SqlDataSourceCommandEventArgs e) { foreach (SqlParameter param in e.Command.Parameters) if (param.Value == null) { e.Cancel = true; lblError.Text = "All fields are required!"; } } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <form id="form1" runat="server"> <div> <asp:Label id="lblError" EnableViewState="false" CssClass="error" Runat="server" /> <asp:DetailsView id="dtlProduct" DataSourceID="srcProducts" DataKeyNames="Id" AllowPaging="true" AutoGenerateEditButton="true" Runat="server" /> <asp:SqlDataSource id="srcProducts" SelectCommand="SELECT * FROM Products" UpdateCommand="UPDATE Products SET Title=@Title,Director=@Director,DateReleased=@DateReleased WHERE Id=@id" ConnectionString="<%$ ConnectionStrings:Products %>" Runat="server" OnUpdating="srcProducts_Updating" /> </div> </form> </body> </html> File: Web.config <configuration> <connectionStrings> <add name="Products" connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" /> </connectionStrings> </configuration>