asp.net FormView控件的使用方法

作者:袖梨 2022-07-02

FormView并不是由那些杂七杂八的列所组成的。你不能给一个FormView添加BoundField或是TemplateField,不过FormView是使用模板来呈现的。我们可以这样来理解FormView,把它当作只含有一个TemplateField的DetailsView控件
<%@ Page Language="C#" AutoEventWireup="true"%>



    Untitled Page


   


        <asp教程:SqlDataSource ID="sourceEmployees"
                           runat="server"
                           ConnectionString="<%$ ConnectionStrings:Northwind %>"
                           ProviderName="System.Data.SqlClient"
                           SelectCommand="SELECT * FROM Employees"/>
       
                 
                    <%# Eval("EmployeeID") %> -
                    <%# Eval("TitleOfCourtesy") %> <%# Eval("FirstName") %>
                    <%# Eval("LastName") %>
                    <%# Eval("Address") %>

                    <%# Eval("City") %>, <%# Eval("Country") %>,
                    <%# Eval("PostalCode") %>

                    <%# Eval("HomePhone") %>
                    <%# Eval("Notes") %>
                 

       

   


File: Web.config



 
     
       
     


更复杂用法




    Untitled Page


   

   

                     DataKeyNames="CustomerID" AllowPaging="True">
           
                CustomerID:
                                     ID="CustomerIDLabel1">
               


                CompanyName:
                                     ID="CompanyNameTextBox">

                ContactName:
                                     ID="ContactNameTextBox">

                ContactTitle:
                                    ID="ContactTitleTextBox">

                Address:
                                     ID="AddressTextBox">

                City:
                                     ID="CityTextBox">

                Region:
                                     ID="RegionTextBox">

                PostalCode:
                                     ID="PostalCodeTextBox">

                Country:
                                     ID="CountryTextBox">

                Phone:
                                     ID="PhoneTextBox">

                Fax:
                                     ID="FaxTextBox">

               

                                     CommandName="update" />
                                     CommandName="cancel" />
           

           
              CustomerID:                                  Text='<%# Bind("CustomerID") %>'>
                                

              CompanyName:                                  Text='<%# Bind("CompanyName") %>'>
                                

              ContactName:                                  Text='<%# Bind("ContactName") %>'>
                                


              ContactTitle:                                  Text='<%# Bind("ContactTitle") %>'>
                                


                                                            Text='<%# Bind("Address") %>'>
                                            

                                                            Text='<%# Bind("City") %>'>
                                            

                                                            Text='<%# Bind("Region") %>'>
                                            

                                                           Runat="server"
                                            Text='<%# Bind("PostalCode") %>'>
                                           

                                                            Text='<%# Bind("Country") %>'>
                                            

               Phone:                                                    Text='<%# Bind("Phone") %>'>
                                                  


               Fax:                                              Text='<%# Bind("Fax") %>'>
                                            


                                                Text="Edit" CommandName="edit" />
           

       

                     SelectCommand="SELECT * FROM [Customers]"
             ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>">
       

   
   

   


File: Web.config


 
 
                     connectionString="Data Source=localhostSQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"
             providerName="System.Data.SqlClient" />
   

 
   
     
       
       
     

   

   
     
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
     

   

   
   
 

相关文章

精彩推荐