<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
<asp:Label ID="lblError" runat="server" SkinID="ErrorLabel" EnableViewState="False"></asp:Label>
<table width="100%" cellpadding="2" cellspacing="0">
<tr valign="top" class="ArticleTitle">
<td style="padding-left:10px;" valign="middle">
asp:FormView control</td>
</tr>
<tr>
<td class="ArticleContents">
FormView is a new data-bound control that is nothing but a templated version of DetailsView control.
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
<div class="ArticleContents">
FormView is a new data-bound control that is nothing but a templated version of DetailsView control.
The major difference between DetailsView and FormView is, here user need to define the rendering template for each item.
<p>
Its properties like <span class="DemoCP">BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. </span>
are implemented through style properites of <tahle> tag.
</p>
Following are some important properties that are very useful.
<table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
<tr>
<th colspan="2" align="left">
Templates of the FormView Control
</th>
</tr>
<tr>
<td class="DemoCP">EditItemTemplate</td>
<td>
The template that is used when a record is being edited.
</td>
</tr>
<tr>
<td class="DemoCP">InsertItemTemplate</td>
<td>
The template that is used when a record is being created.
</td>
</tr>
<tr>
<td class="DemoCP">ItemTemplate</td>
<td>
The template that is used to render the record to display only.
</td>
</tr>
<tr>
<th colspan="2" align="left">
Methods of the FormView Control
</th>
</tr>
<tr>
<td class="DemoCP">ChangeMode</td>
<td>
ReadOnly/Insert/Edit. Change the working mode of the control from the current to the defined FormViewMode type.
</td>
</tr>
<tr>
<td class="DemoCP">InsertItem</td>
<td>
Used to insert the record into database. This method must be called when the DetailsView control is in insert mode.
</td>
</tr>
<tr>
<td class="DemoCP">UpdateItem</td>
<td>
Used to update the current record into database. This method must be called when DetailsView control is in edit mode.
</td>
</tr>
<tr>
<td class="DemoCP">DeleteItem</td>
<td>
Used to delete the current record from database.
</td>
</tr>
</table>
<!-- START - Demo Section -->
<table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
<tr>
<td class="DemoTitle">
DEMO : FormView
</td>
<td align="right">
<a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/formview.aspx" target="_blank">Show Source Code</a>
</td>
</tr>
<tr valign="Top">
<td>
<asp:FormView ID="FormView1" runat="server" CellPadding="4" ForeColor="#333333"
DataKeyNames="AutoID" DataSourceID="SqlDataSource1" AllowPaging="true" Caption="Try Inserting Records into Database">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><%# Eval("Name") %></td>
</tr>
<tr>
<td>Address</td>
<td><%# Eval("Address") %></td>
</tr>
<tr>
<td>Phone</td>
<td><%# Eval("Phone") %></td>
</tr>
<tr>
<td>City</td>
<td><%# Eval("City") %></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnEdit" runat="Server" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnInsert" runat="Server" CommandName="New" Text="New" />
<asp:Button ID="btnDelete" runat="Server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure to Delete?');" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Name")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Address")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Phone")%>'></asp:TextBox></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextBox4" runat="Server" Text='<%# Bind("City")%>'></asp:TextBox></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnUpdate" runat="Server" CommandName="Update" Text="Update" />
<asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Name")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Address")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Phone")%>'></asp:TextBox></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextBox4" runat="Server" Text='<%# Bind("City")%>'></asp:TextBox></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnSave" runat="Server" CommandName="insert" Text="Insert" />
<asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnStr %>'
SelectCommand="Select * FROM SampleForTutorials ORDER BY AutoID"
DeleteCommand="Delete FROM SampleForTutorials WHERE AutoID = @AutoID"
UpdateCommand="UPDATE SampleForTutorials SET Name = @Name, Address = @Address, Phone = @Phone, City = @City WHERE AutoID = @AutoID"
InsertCommand="INSERT INTO SampleForTutorials (Name, Address, Phone, City) VALUES (@Name, @Address, @Phone, @City)">
<DeleteParameters>
<asp:Parameter Name="AutoID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="AutoID" Type="Int32" />
<asp:Parameter Name="Name" Type="string" Size="50" />
<asp:Parameter Name="Address" Type="string" Size="200" />
<asp:Parameter Name="Phone" Type="string" Size="50" />
<asp:Parameter Name="City" Type="string" Size="20" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="string" Size="50" />
<asp:Parameter Name="Address" Type="string" Size="200" />
<asp:Parameter Name="Phone" Type="string" Size="50" />
<asp:Parameter Name="City" Type="string" Size="20" />
<asp:Parameter Name="AutoID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
</td>
<td>
</td>
</tr>
<tr>
<td colspan="2">
<pre>
// FormView control ////////////////////////////////
<asp:FormView ID="FormView1" runat="server" CellPadding="4" ForeColor="#333333"
DataKeyNames="AutoID" DataSourceID="SqlDataSource1" AllowPaging="true">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><%# Eval("Name") %></td>
</tr>
<tr>
<td>Address</td>
<td><%# Eval("Address") %></td>
</tr>
<tr>
<td>Phone</td>
<td><%# Eval("Phone") %></td>
</tr>
<tr>
<td>City</td>
<td><%# Eval("City") %></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnEdit" runat="Server" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnInsert" runat="Server" CommandName="New" Text="New" />
<asp:Button ID="btnDelete" runat="Server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure to Delete?');" />
</td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Name")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Address")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Phone")%>'></asp:TextBox></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextBox4" runat="Server" Text='<%# Bind("City")%>'></asp:TextBox></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnUpdate" runat="Server" CommandName="Update" Text="Update" />
<asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table border="1">
<tr>
<td>AutoID</td>
<td><%# Eval("AutoID") %></td>
</tr>
<tr>
<td>Name</td>
<td><asp:TextBox ID="TextBox1" runat="Server" Text='<%# Bind("Name")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="TextBox2" runat="Server" Text='<%# Bind("Address")%>'></asp:TextBox></td>
</tr>
<tr>
<td>Phone</td>
<td><asp:TextBox ID="TextBox3" runat="Server" Text='<%# Bind("Phone")%>'></asp:TextBox></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextBox4" runat="Server" Text='<%# Bind("City")%>'></asp:TextBox></td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnSave" runat="Server" CommandName="insert" Text="Insert" />
<asp:Button ID="Button1" runat="Server" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:FormView>
// SqlDataSource Control ////////////////////////////////
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:ConnStr %>'
SelectCommand="Select * FROM SampleForTutorials ORDER BY [Name]"
DeleteCommand="Delete FROM SampleForTutorials WHERE AutoID = @AutoID"
UpdateCommand="UPDATE SampleForTutorials SET Name = @Name, Address = @Address, Phone = @Phone, City = @City WHERE AutoID = @AutoID"
InsertCommand="INSERT INTO SampleForTutorials (Name, Address, Phone, City) VALUES (@Name, @Address, @Phone, @City)">
<DeleteParameters>
<asp:Parameter Name="AutoID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="AutoID" Type="Int32" />
<asp:Parameter Name="Name" Type="string" Size="50" />
<asp:Parameter Name="Address" Type="string" Size="200" />
<asp:Parameter Name="Phone" Type="string" Size="50" />
<asp:Parameter Name="City" Type="string" Size="20" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="string" Size="50" />
<asp:Parameter Name="Address" Type="string" Size="200" />
<asp:Parameter Name="Phone" Type="string" Size="50" />
<asp:Parameter Name="City" Type="string" Size="20" />
<asp:Parameter Name="AutoID" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
</pre>
</td>
</tr>
</table>
<!-- END - Demo Section -->
</div>
<br />
<script language="javascript" type="text/javascript">
function GiveAlertToUser()
{
alert("Hi Dear, Client side method worked.");
}
</script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>
Go Top