How to use ASP.net FormView controls

Source: Internet
Author: User

FormView is not made up of those assorted columns. You cannot add BoundField or TemplateField to a FormView, but FormView is rendered using a template. We can do this to understand FormView as a DetailsView control that contains only one TemplateField.
<%@ Page language= "C #" autoeventwireup= "true"%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en" "Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

<title>untitled page</title>
<body>
<form id= "Form1" runat= "Server" >
<asp Tutorial: SqlDataSource id= "Sourceemployees"
runat= "Server"
connectionstring= "<%$ connectionstrings:northwind%>"
Providername= "System.Data.SqlClient"
Selectcommand= "SELECT * from Employees"/>
<asp:formview id= "FormView1" runat= "Server" datasourceid= "Sourceemployees" >
<ItemTemplate>
<%# Eval ("EmployeeID")%>-
<%# eval ("TitleOfCourtesy")%> <%# eval ("FirstName")%>
<%# Eval ("LastName")%>
<%# Eval ("address")%><br/>
<%# eval ("City")%> <%# eval ("Country")%>
<%# Eval ("PostalCode")%><br/>
<%# Eval ("HomePhone")%>
<%# Eval ("Notes")%>
</ItemTemplate>
</asp:FormView>
</form>
</body>

File:Web.config

<?xml version= "1.0"?>
<configuration xmlns= "http://schemas.microsoft.com/.NetConfiguration/v2.0" >
<appSettings/>
<connectionStrings>
<add name= "Northwind" connectionstring= "Data source=localhost;initial catalog=northwind;integrated Security=SSPI "/>
</connectionStrings>
</configuration>


More complex usage

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>untitled page</title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:formview id= "FormView1" runat= "Server" datasourceid= "SqlDataSource1"
Datakeynames= "CustomerID" allowpaging= "True" >
<EditItemTemplate>
CustomerID:
<asp:label text= ' <%# Eval ("CustomerID")%> ' runat= ' server '
Id= "CustomerIDLabel1" >
</asp:label><br/>
CompanyName:
<asp:textbox text= ' <%# Bind ("CompanyName")%> ' runat= ' server '
Id= "Companynametextbox" ></asp:textbox><br/>
ContactName:
<asp:textbox text= ' <%# Bind ("ContactName")%> ' runat= ' server '
Id= "Contactnametextbox" ></asp:textbox><br/>
ContactTitle:
<asp:textbox text= ' <%# Bind ("ContactTitle")%> ' runat= ' server '
Id= "Contacttitletextbox" ></asp:textbox><br/>
Address:
<asp:textbox text= ' <%# Bind (' address ')%> ' runat= ' server '
Id= "Addresstextbox" ></asp:textbox><br/>
City:
<asp:textbox text= ' <%# Bind ("City")%> ' runat= ' server '
Id= "Citytextbox" ></asp:textbox><br/>
Region:
<asp:textbox text= ' <%# Bind ("Region")%> ' runat= ' server '
Id= "Regiontextbox" ></asp:textbox><br/>
PostalCode:
<asp:textbox text= ' <%# Bind ("PostalCode")%> ' runat= ' server '
Id= "Postalcodetextbox" ></asp:textbox><br/>
Country:
<asp:textbox text= ' <%# Bind ("Country")%> ' runat= ' server '
Id= "Countrytextbox" ></asp:textbox><br/>
Phone:
<asp:textbox text= ' <%# Bind ("Phone")%> ' runat= ' server '
Id= "Phonetextbox" ></asp:textbox><br/>
Fax:
<asp:textbox text= ' <%# Bind ("Fax")%> ' runat= ' server '
Id= "Faxtextbox" ></asp:textbox><br/>
<br/>
<asp:button id= "Button2" runat= "Server" text= "Update"
Commandname= "Update"/>
<asp:button id= "Button3" runat= "Server" text= "Cancel"
Commandname= "Cancel"/>
</EditItemTemplate>
<ItemTemplate>
Customerid:<asp:label id= "Customeridlabel" runat= "Server"
Text= ' <%# Bind ("CustomerID")%> ' >
</asp:Label>
Companyname:<asp:label id= "Companynamelabel" runat= "Server"
Text= ' <%# Bind ("CompanyName")%> ' >
</asp:Label>
Contactname:<asp:label id= "Contactnamelabel" runat= "Server"
Text= ' <%# Bind ("ContactName")%> ' >
</asp:label><br/>
Contacttitle:<asp:label id= "Contacttitlelabel" runat= "Server"
Text= ' <%# Bind ("ContactTitle")%> ' >
</asp:label><br/>
<asp:label id= "Addresslabel" runat= "Server"
Text= ' <%# Bind ("address")%> ' >
</asp:Label></td>
<asp:label id= "Citylabel" runat= "Server"
Text= ' <%# Bind ("City")%> ' >
</asp:Label></td>
<asp:label id= "Regionlabel" runat= "Server"
Text= ' <%# Bind ("Region")%> ' >
</asp:Label></td>
<asp:label id= "Postalcodelabel"
runat= "Server"
Text= ' <%# Bind ("PostalCode")%> ' >
</asp:Label>
<asp:label id= "Countrylabel" runat= "Server"
Text= ' <%# Bind ("Country")%> ' >
</asp:Label></td>
Phone:<asp:label id= "Phonelabel" runat= "Server"
Text= ' <%# Bind ("Phone")%> ' >
</asp:label><br/>
Fax:<asp:label id= "Faxlabel" runat= "Server"
Text= ' <%# Bind ("Fax")%> ' >
</asp:label><br/>
<asp:button id= "Button1" runat= "Server"
text= "edit" commandname= "edit"/>
</ItemTemplate>
</asp:FormView>
<asp:sqldatasource id= "SqlDataSource1" runat= "Server"
Selectcommand= "SELECT * from [Customers]"
connectionstring= "<%$ connectionstrings:appconnectionstring1%>" >
</asp:SqlDataSource>

</div>
</form>
</body>

File:Web.config

<configuration>
<appSettings/>
<connectionStrings>
<add name= "AppConnectionString1"
connectionstring= "Data source=localhostsqlexpress;initial catalog=northwind;integrated Security=True"
Providername= "System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug= "true" strict= "false" explicit= "true" >
<codeSubDirectories>
<add directoryname= "VB" ></add>
<add directoryname= "CS" ></add>
</codeSubDirectories>
</compilation>
<pages>
<namespaces>
<clear/>
<add namespace= "System"/>
<add namespace= "System.Collections"/>
<add namespace= "System.Collections.Specialized"/>
<add namespace= "System.Configuration"/>
<add namespace= "System.Text"/>
<add namespace= "System.Text.RegularExpressions"/>
<add namespace= "system.web"/>
<add namespace= "System.Web.Caching"/>
<add namespace= "System.Web.SessionState"/>
<add namespace= "System.Web.Security"/>
<add namespace= "System.Web.Profile"/>
<add namespace= "System.Web.UI"/>
<add namespace= "System.Web.UI.WebControls"/>
<add namespace= "System.Web.UI.WebControls.WebParts"/>
<add namespace= "System.Web.UI.HtmlControls"/>
</namespaces>
</pages>
<authentication mode= "Windows" ></authentication>
<identity impersonate= "true"/>
</system.web>
</configuration>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.