Mega Code Archive

 
Categories / ASP.Net Tutorial / ADO Net Database
 

Using the ASP NET FormParameter Object

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <script runat="server">     void Page_Load()     {         if (Request.Form["AddProduct"] != null)             srcProducts.Insert();     } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server">     <title>Show FormParameter</title> </head> <body>     <form action="ShowFormParameter.aspx" method="post">         <label for="txtTitle">Product Title:</label>         <input name="txtTitle" />         <label for="txtDirector">Product Director:</label>         <input name="txtDirector" />         <input name="AddProduct" type="submit" value="Add Product" />     </form>     <form id="form1" runat="server">     <div>     <asp:GridView         id="grdProducts"         DataSourceID="srcProducts"         Runat="server" />     <asp:SqlDataSource         id="srcProducts"         SelectCommand="SELECT * FROM Products"         InsertCommand="INSERT Products (Title,Director,CategoryId,DateReleased)             VALUES (@Title,@Director,0,'12/25/1966')"         ConnectionString="<%$ ConnectionStrings:Products %>"         Runat="server">         <InsertParameters>             <asp:FormParameter Name="Title"                 FormField="txtTitle" DefaultValue="Untitled" />             <asp:FormParameter Name="Director"                 FormField="txtDirector" DefaultValue="Allen Smithee" />         </InsertParameters>     </asp:SqlDataSource>     </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>