日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

FormView控件

 行走在理想邊緣 2019-02-15

FormView控件是ASP.NET 2.0工具箱引入的,它的工作方式類似于DetailsView控件,也是顯示綁定數(shù)據(jù)源控件中的一個(gè)數(shù)據(jù)項(xiàng),并可以添加、編輯和刪除數(shù)據(jù)。它比較獨(dú)特的 地方是在定制模板中顯示數(shù)據(jù),可以更多地控制數(shù)據(jù)的顯示和編輯方式。圖7-35顯示了在Visual Studio中編輯的FormView控件ItemTemplate。從中可以看出,我們能完全控制數(shù)據(jù)的顯示方式。FormView控件還包含 EditItemTemplate和InsertItemTemplate,它可以確定控件在進(jìn)入編輯或插入模式下的顯示方式。

 
(點(diǎn)擊查看大圖)圖  7-35

圖7-35顯示了Visual Studio中的FormView控件。圖7-36顯示了FormView控件的ItemTemplate,表示在Visual Studio中設(shè)計(jì)的定制布局。

 
圖  7-36

在圖7-37中,該控件處于編輯模式,顯示了標(biāo)準(zhǔn)的EditItemTemplate布局。

 
圖  7-37

程序清單7-58是在設(shè)計(jì)FormView控件的定制ItemTemplate時(shí)Visual Studio生成的代碼。

程序清單7-58  使用FormView控件顯示和編輯數(shù)據(jù)

<%@ Page Language="C#" %>
<html xmlns="http://www./1999/xhtml
" >
<head runat="server">
<title>Using the FormView control</title>
</head>
<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="Button"
CommandName="update" />
<asp:Button ID="Button3" Runat="server" Text="Button"
CommandName="cancel" />
</EditItemTemplate>
<ItemTemplate>
<table width="100%">
<tr>
<td style="width: 439px">
<b>
<span style="font-size: 14pt">Customer Information</span>
</b>
</td>
<td style="width: 439px" align="right">
CustomerID:
<asp:Label ID="CustomerIDLabel" Runat="server"
Text='<%# Bind("CustomerID") %>'>
</asp:Label></td>
</tr>
<tr>
<td colspan="2">
CompanyName:
<asp:Label ID="CompanyNameLabel" Runat="server"
Text='<%# Bind("CompanyName") %>'>
</asp:Label><br />
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 />
<br />
<table width="100%"><tr>
<td colspan="3">
<asp:Label ID="AddressLabel" Runat="server"
Text='<%# Bind("Address") %>'>
</asp:Label></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Label ID="CityLabel" Runat="server"
Text='<%# Bind("City") %>'>
</asp:Label></td>
<td style="width: 100px">
<asp:Label ID="RegionLabel" Runat="server"
Text='<%# Bind("Region") %>'>
</asp:Label></td>
<td style="width: 100px">
<asp:Label ID="PostalCodeLabel"
Runat="server"
Text='<%# Bind("PostalCode") %>'>
</asp:Label>
</td>
</tr>
<tr>
<td style="width: 100px" valign="top">
<asp:Label ID="CountryLabel" Runat="server"
Text='<%# Bind("Country") %>'>
</asp:Label></td>
<td style="width: 100px"></td>
<td style="width: 100px">
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 />
</td>
</tr></table>
<asp:Button ID="Button1" Runat="server"
Text="Button" CommandName="edit" />
</td>
</tr></table>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT * FROM [Customers]"
ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>">
</asp:SqlDataSource>

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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多