没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|其它|编辑:郝浩|2009-06-11 11:33:20.000|阅读 1649 次
概述:ASP.NET的新ListView控件为显示和CRUD数据库操作提供了基于模板的布局,使其成为构建以数据为中心的Web应用程序的方法。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
在Listing 1中,通过设置ConnectionString 和SelectCommand 属性的适当值,SqlDataSource控件检索来自AdventureWorks数据库的Product表格的数据。ConnectionString属性通过一个ASP.NET表达式从web.config中获得连接字串。在我测试机器上,连接字串在web.config中定义如下:
< connectionStrings>
< add name="AdventureWorks"
connectionString="server=localhost;uid=sa;
pwd=thiru;database=AdventureWorks;"/>
< /connectionStrings>
当设置SqlDataSource属性之后,下一步通过ListView控件显示那个数据。这里的标记包括在LayoutTemplate中:
< LayoutTemplate>
< table cellpadding="2" runat="server" id="tblProducts"
style="width:460px">
< tr runat="server" id="itemPlaceholder">
< /tr>
< /table>
< asp:DataPager runat="server" ID="DataPager" PageSize="3">
< Fields>
< asp:NumericPagerField ButtonCount="10"
PreviousPageText="< --" NextPageText="-->" />
< /Fields>
< /asp:DataPager>
< /LayoutTemplate>
LayoutTemplate为从ListView中产生的输出定义一个容器。除了定义ListView控件的整体布局的table控制,LayoutTemplate也定义了< asp:DataPager>控件,为ListView控件提供了页面功能。DataPager控件标页数据并为任何实施IPageableItemContainer接口(ListView控制的)的数据绑定控件显示导航控件。
这有两个将DataPager控件和一个数据绑定控件结合在一起的方法:
将DataPager控件的PagedControlID属性设置到数据绑定控件的名字。
在数据绑定控件等级里面放入DataPager控件。对于Listview控件,你可以将DataPager控件放入LayoutTemplate元素中。
设置DataPager的PageSize属性来控制项为每个数据页面显示的项目数量。通过设置QueryStringField属性,你也可以改变网页被提交到服务器的方法。
在DataPager控制中,你指定NumericPageField模板,它确保用户通过选择页数来导航特定的页面。
< asp:NumericPagerField ButtonCount="10"
PreviousPageText="< --"
NextPageText="-->" />
用Eval()语句,通过检索来自数据源控件的数据,ItemTemplate元素为每个记录的细节提供标记。
图1 显示的是在浏览器中导航页面所产生的输出。
用ListView控件编辑数据
如你所见,通过一个ListView控件显示数据是相对直接的,但是你也可以让用户在一个ListView中编辑数据。添加一个新的叫做ListViewEditExample.aspx 的ASP.NET页面到一个简单的网站中并修改它的代码如Listing 2所示:
HTML (ASP.NET)
Listing 2. Editable ListView:
This page sets up an editable ListView, where users can update data from the AdventureWorks database.
< %@ Page Language="C#" %>
< script runat="server">
void deptsView_ItemUpdated(object sender,
ListViewUpdatedEventArgs e)
{
lblResult.Text = e.AffectedRows.ToString() +
" row(s) successfully updated";
}
void deptsView_PagePropertiesChanged(object sender, EventArgs e)
{
//Set the text to empty when navigating to a different page
lblResult.Text = "";
}
< /script>
< html xmlns="http://www.w3.org/1999/xhtml">
< head runat="server">
< link rel="Stylesheet" type="text/css" href="StyleSheet.css" />
< title>Editing Data using ListView Control< /title>
< /head>
< body>
< form id="form1" runat="server">
< div>
< asp:ListView ID="ContactsListView" DataSourceID="deptSource"
DataKeyNames="DepartmentID" runat="server"
OnItemUpdated="deptsView_ItemUpdated"
OnPagePropertiesChanged="deptsView_PagePropertiesChanged">
< LayoutTemplate>
< table cellpadding="2" width="640px" border="1"
runat="server" id="tblProducts">
< tr id="row1" runat="server" class="header">
< th id="header2" runat="server">Name< /th>
< th id="header3" runat="server">Group Name< /th>
< th id="header1" runat="server">Action< /th>
< /tr>
< tr runat="server" id="itemPlaceholder" />
< /table>
< asp:DataPager runat="server" ID="deptsDataPager"
PageSize="3">
< Fields>
< asp:NextPreviousPagerField ShowFirstPageButton="True"
ShowLastPageButton="True" FirstPageText="|< < "
LastPageText=" >>|" NextPageText=" > "
PreviousPageText=" < " />
< /Fields>
< /asp:DataPager>
< /LayoutTemplate>
< ItemTemplate>
< tr id="row2" runat="server">
< td>
< asp:Label ID="lblName" runat="Server"
Text='< %#Eval("Name") %>' />
< /td>
< td valign="top">
< asp:Label ID="lblGroupName" runat="Server"
Text='< %#Eval("GroupName") %>' />
< /td>
< td>
< asp:LinkButton ID="btnEdit" runat="Server" Text="Edit"
CommandName="Edit" />
< /td>
< /tr>
< /ItemTemplate>
< EditItemTemplate>
< tr style="background-color: #ADD8E6">
< td>
< asp:TextBox ID="txtName" runat="server"
Text='< %# Bind("Name") %>'
MaxLength="50" />< br />
< /td>
< td>
< asp:TextBox ID="txtGroupName" runat="server" Text='< %#
Bind("GroupName") %>' MaxLength="50" />< br />
< /td>
< td>
< asp:LinkButton ID="btnUpdate" runat="server"
CommandName="Update" Text="Update" />?
< asp:LinkButton ID="btnCancel" runat="server"
CommandName="Cancel" Text="Cancel" />
< /td>
< /tr>
< /EditItemTemplate>
< /asp:ListView>
< asp:SqlDataSource ID="deptSource" runat="server"
ConnectionString="< %$ ConnectionStrings:AdventureWorks %>"
SelectCommand="SELECT [DepartmentID],[Name],[GroupName] FROM
HumanResources.Department" UpdateCommand="UPDATE
HumanResources.Department SET Name = @Name,
GroupName = @GroupName WHERE DepartmentID = @DepartmentID">
< /asp:SqlDataSource>
< br />< br />
< asp:Label runat="server" ID="lblResult" Text=""
Font-Bold="true" />
< /div>
< /form>
< /body>
< /html>
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com
文章转载自:IT专家网面对“数字中国”建设和中国制造2025战略实施的机遇期,中车信息公司紧跟时代的步伐,以“集约化、专业化、标准化、精益化、一体化、平台化”为工作目标,大力推进信息服务、工业软件等核心产品及业务的发展。在慧都3D解决方案的实施下,清软英泰建成了多模型来源的综合轻量化显示平台、实现文件不失真的百倍压缩比、针对模型中的大模型文件,在展示平台上进行流畅展示,提升工作效率,优化了使用体验。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
本站的模型资源均免费下载,登录后即可下载。模型仅供学习交流,勿做商业用途。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 渝公网安备
50010702500608号