Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
DevExpress UI Controls
Search :       Advanced Search »
Home » ASP.NET and Web » FormView control Templates in ASP.NET 2.0

FormView control Templates in ASP.NET 2.0

This article explain you the type of templates available in FormView.

Page Views : 52988
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

We use the FormView control for display a single record from the data source; there are seven types of Templates in which most of the Templates are optional.

 

You must create a Template for the mode in which the FormView control is configured. For example, a FormView control that supports updating records must have an EditItemTemplate defined.

 

Types of Templates: 

  • HeaderTemplate
  • FooterTemplate
  • ItemTemplate
  • InsertItemTemplate
  • EditItemTemplate
  • EmptyDataTemplate
  • PagerTemplate

HeaderTemplate:


Header Template defines the contents which we want to display in the header row of the FormView Control.

 

FooterTemplate:

Footer Template defines the contents which we want to display in the footer row of the FormView Control.


ItemTemplate:

 

ItemTemplates defines the contents for the FormView row when it is in read only mode. This template basically used for display the existing data from the data source.

 

InsertItemTemplate:

 

InsertItemTemplates defines the contents for the FormView row when it is in insert mode. This template contains the input controls and commands for inserting the new record.

 

EditItemTemplate:

 

EditItemTemplates defines the contents for the FormView row when it is in edit mode. This template contains the input controls and commands for editing the existing record.

 

EmptyDataTemplate:

 

EmptyDataTemplate basically used for showing the alert to the user if there is no record in the bound column.

 

PagerTemplate:

 

PagerTemplate defines the content for the pager row when the "AllowPaging" property is true. It also contains the controls by using that, user can navigate to another record.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 Article Extensions
Contents added by manik prabhu on Sep 30, 2009

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<div>

<asp:FormView ID="FormView1" runat="server" DataKeyNames="hostid" DataSourceID="SqlDataSource1" AllowPaging="True" Height="60px" Width="266px">

<EditItemTemplate>

hostid:

<asp:Label ID="hostidLabel1" runat="server" Text='<%#Eval("hostid") %>'></asp:Label><br />

hostingname:

<asp:TextBox ID="hostingnameTextBox" runat="server" Text='<%# Bind("hostingname") %>'>

</asp:TextBox><br />

<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"

Text="Update">

</asp:LinkButton>

<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel">

</asp:LinkButton>

</EditItemTemplate>

<InsertItemTemplate>

hostingname:

<asp:TextBox ID="hostingnameTextBox" runat="server" Text='<%# Bind("hostingname") %>'>

</asp:TextBox><br />

<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"

Text="Insert">

</asp:LinkButton>

<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"

Text="Cancel">

</asp:LinkButton>

</InsertItemTemplate>

<ItemTemplate>

hostid:

<asp:Label ID="hostidLabel" runat="server" Text='<%# Eval("hostid") %>'></asp:Label><br />

hostingname:

<asp:Label ID="hostingnameLabel" runat="server" Text='<%# Bind("hostingname") %>'>

</asp:Label><br />

<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="true" CommandArgument="Edit">Edit</asp:LinkButton>

</ItemTemplate>

<EmptyDataTemplate>

No Records Found

</EmptyDataTemplate>

<PagerTemplate>

<asp:LinkButton ID="btnFirst" CommandName="Page" CommandArgument="First" Text="First" runat="server"/>

<asp:LinkButton ID="btnPrevious" CommandName="Page" CommandArgument="Prev" Text="Previous" runat="server"/>

<asp:LinkButton ID="btnNext" CommandName="Page" CommandArgument="Next" Text="Next" runat="server"/>

<asp:LinkButton ID="btnLast" CommandName="Page" CommandArgument="Last" Text="Last" runat="server"/>

</PagerTemplate>

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:hostnowConnectionString %>"

SelectCommand="SELECT * FROM [tbl_Hosting]">

</asp:SqlDataSource>

&nbsp;

</div>

</form>

</body>

</html>

 [Top] Rate this article
 
 About the author
 
Yogesh Verma

Yogesh is working as a SharePoint Specialist. Yogesh's background includes Master's in Computer Science and Applications and B. Sc. Maths. He is working on Sharepoint, Moss 2007, ASP.NET  and C #, SQL.

Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Team Foundation Server Hosting
Become a Sponsor
 Comments
form view examples by charanpreet On March 20, 2008
please send me the example of form view control in c#. thanks & regards charanpreet
Reply | Email | Modify 
Form View by zeeshan On August 16, 2008
I need a example of form view in which i want to calculate some integer values i.e i put calues in two fields and sum of the two fields autometically display in the 3rd feild.... Plz send me that example ........... Thanx
Reply | Email | Modify 
Formview edit,update,delete Code Sample in vb.net by Narayan On August 20, 2008
please send me Formview edit,update,delete Code Sample in vb.net by using connection string,command objects.
Reply | Email | Modify 
Formview to upload image by Sharmila On December 21, 2009
Hi,

How to upload and display image thru formview control? I tried lot but its neither giving me error nor displaying image. In Sql database I have stored image with Image field type.

<asp:FormView ID="frmProfile" runat = "server" DataSourceID ="SqlDataSource1">

 

<ItemTemplate >

<table border ="0">

<tr><td><asp:LinkButton ID="lnkEdit" runat ="server" Text="Edit" CausesValidation ="false" CommandName ="Edit" /></td>

</tr><tr><td><asp:Image ID="imgProfile" runat ="server" ImageUrl ='<%# Eval("photo")%>' AlternateText ="Not Available" /></td>


</ItemTemplate>

<EditItemTemplate >

<table border ="0">

<tr><td><asp:LinkButton ID="lnkUpdate" runat="server" Text="Update" CausesValidation ="true" CommandName ="Update" /> </td>

<td><asp:LinkButton ID="lnkCancel" runat ="server" Text="Cancel" CausesValidation ="false" CommandName ="Cancel" /></td></tr> <hr />

<tr><td><asp:Image ID="imgProfileEdit" Width = "150" Height = "125" ImageUrl ='<%# Eval("photo")%>' runat = "server" AlternateText ="Not Available" /> </td>

</table>

</EditItemTemplate>

</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat ="server" ConnectionString ="<%$ ConnectionStrings:cnnvastu %>" SelectCommand ="LoadData" UpdateCommand ="updateProfile" UpdateCommandType ="StoredProcedure" SelectCommandType="StoredProcedure">

my VB code is -

Public Sub frmProfile_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles frmProfile.DataBound

Dim row As FormViewRow = frmProfile.Row

Dim rowview As DataRowView = CType(frmProfile.DataItem, DataRowView)

Dim profilePhoto As Image = Nothing

Select Case frmProfile.CurrentMode

Case FormViewMode.ReadOnly

profilePhoto = CType(row.FindControl("imgProfile"), Image)

Case FormViewMode.Edit

profilePhoto = CType(row.FindControl("imgProfileEdit"), Image)

Case Else

End Select

If profilePhoto IsNot Nothing Then

profilePhoto.ToolTip = "Not Available"

End If

End Sub



Let me know why its not working.. its displaying AlternateText every time.

Reply | Email | Modify 
DevExpress Free UI Controls
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.