ASPNET程序设计教程C版崔淼ASPNET常用控件新
- 格式:ppt
- 大小:5.79 MB
- 文档页数:5
常⽤控件有哪些,有什么作⽤。
打开VS010,我们可以看到它提供的Web控件为:标准,数据,验证,导航,登陆,Webparts(⽹页组件),AJAX Extension,Dynamic(动态) Data,Reporting(报表),HTML,General(常规,综合的)这⼏类。
⼀.standard1、Label控件:标签,主要作⽤在于显⽰⽂字讯息,标签控件显⽰的⽂字不能直接进⾏修改,要修改的话只能在设计阶段进⾏!常⽤属性:Id:此控件名称 Text:要显⽰的⽂字信息 ToolTip:⿏标放在控件上时显⽰的提⽰信息 Visible:运⾏时是否可见2、TextBox:⽂本框:既可以⽤来显⽰⽂字,还能够在⽂字框中输⼊⽂字常⽤属性:AutoPostBack:⽂本修改后是否⾃动回发到服务器 MaxLength:可输⼊的最⼤字符数 TextMode:⾏为模式,有SingleLine,MultiLine,Password三个值3、Button:按钮常⽤属性:CausesValidation:是否启动验证点击Button按钮控件时会触发click和command事件,两者的区别是,如果要激发command事件,需要设置commandArgument、commandName属性值,⽽且可以对多个button控件同时指定⼀个command事件,通过CommandName的值不同来触发不同的操作;但是click事件,每⼀个控件只有⼀个⽅法,⽽且不能同⽤例。
4、LinkButton控件:在页⾯上显⽰为⼀个超链接5、ImageButton控件:以图⽚形式显⽰ ImageUrl属性指定图⽚路径6、HyperLink:超链接控件 NavigateUrl属性指定定位到的Url7、Dropdown List:下拉菜单8、ListBox列表框:常⽤属性:1、BackColor 属性:⽤于显⽰ListBox控件中的⽂本和图形的背景颜⾊,默认为⽩⾊(Window)2、BorderStyle 属性:控制在列表框ListBox周围绘制的边框的类型,其枚举值为下⾯三个:BorderStyle.None——⽆边框BorderStyle.FixedSingle——单⾏边框BorderStyle.Fixed3D——三维边框默认值为BorderStyle.Fixed3D。
选择题1.广泛用于网站编程的语言是3P,以下()不是3P语言之一。
A.ASP B.PHPC.PB D.JSP2.采用C#、Visual Basic语言作为脚本,执行时一次编译,可以()执行。
A.一次B.多次C.两次D.三次3.()是.NET的标准语言。
A.C++B.C#C.Visual Basic D.Java4.默认的页面文件扩展名是()。
A.asp B.aspnetC.net D.aspx5.Windows2003内置了.Net Framework的版本是()。
A.1.1B.2.0C.3.0D.3.56.()是.NET的核心。
A..NET Framework B.C#C.FLC D.CLR7.IL是指()。
A.框架类库B.中间语言C.公共语言运行库D.框架8.NET框架的核心是()。
A..NET Framework B.ILC.FLC D.CLR9.程序代码编译的时候,.NET框架先将源代码编译为()。
A.汇编语言B.ILC.CS代码D.机器语言10.以下()不是.NET平台的开发工具。
A.C#.NET B.C.VC++.NET D.PHP1.Visual Studio2010不可用于开发()程序。
A.Web应用程序B.3D动画C.XML Web Serivce D.Windows应用程序2.Visual Studio没有内置的编程语言是()。
A.Visual C#.NET B.C.Visual D.Visual J#.NET3.在Visual Studio中新增Web页面的方法是:右击解决方案资源管理器,然后单击()。
A.添加新项B.添加现有项C.添加引用D.添加Web引用4.Visual Studio2010的MSDN是()系统。
A.向导B.报表C.数据库D.帮助5.文件存储的HTTP方式,文件实际存储在()。
A.本地计算机硬盘B.本地IIS默认目录下C.服务器上D.以上都不对6.在Visual Studio2010中不调试直接执行程序的快捷键是()。
ASPNET 五大数据控件1. 插入功能方面:DetailsView 和FormView 具有插入功能,其它控件没有2. 模板DataList\FormView\Repeater 三种必须编辑模板,而GridView 和DetailsView 只有在将列转换成模板列以后才会显现各种模板.3. 自动分页功能GridView ,DetailsView 和FormView 差不多上2.0 版本新增控件,内置了分页,排序等等功能,其他需要手工定义4. 数据出现方式: GridView,DataList,Repeator 用于出现多列数据,DetailsView,FormView 用于出现单列数据,即常用的数据明细.DataList和Reapter都需要编辑模板列,而在模板列当中能够添加Text Box,同时能够指定TextBox的ID从而实现提取用户输入的值,然而Data Grid 和GridView 两个件是不需要编辑模板的,它的编辑功能是自动生成的我们无法明白那些文本框的ID ,也就无法通过ID 来猎取用户的输入,那么能够通过对单元格的引用来实现:private void DataGrid1_UpdateCommand(object source,xx){stri ng bkid二DataGrid1.DataKeys[e.ltem」teml ndex].toStri ng();〃提取主键string bktitle=((TextBox)e.ltem.Cells[1].Controls[0]).Text;// 提取用户的输入}一. 进入编辑状态:DataList1.EditItemIndex = e.Item.ItemIndex;DataGrid1.EditItemIndex = e.Item.ItemIndex;GridView1.EditIndex = e.NewEditIndex;DetailsViewl.Cha ngeMode(DetailsViewMode.Edit);// 进入编辑状态DetailsViewl.Cha ngeMode(DetailsViewMode.Read On ly);//退出编辑状态二. 设置主键:DataList1.DataKeyField = "bkid";DataGrid1.DataKeyField = "bkid";string[] str={"bkid"};GridView1.DataKeyNames = str;三. 提取主键:string bkid = DataList1.DataKeys[e.Item.ItemIndex].ToString();//DataLis t string bkid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();//DataGr id string bkid = GridView1.DataKeys[e.RowIndex].Value.ToString();//Grid Viewstring bkid = DetailsView1.DataKey[0].ToString();四. 查找控件:string bktitle = ((TextBox)e.Item.FindControl("txtTile")).Text;//DataListstring bktitle = ((TextBox)e.Item.Cells[1].Controls[0]).Text;//DataGridstring bktitle = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;string bktitle = ((TextBox)DetailsView1.Rows[1].Cells[1].Controls[0]).Te xt;注意查找控件有两种方法:(各数据绑定控件的都能够用下面两种方法进行查找)1.如果明白控件的ID 能够用这种方法((TextBox)e.Item.FindControl("txtTile")).Text;// 这是查找2.如果不明白控件的ID 可用这种方法((TextBox)e.Item.Cells[1].Controls[0]).Text;// 这是索引五.给删除按钮添加确认:protected void DataList1_ItemDataBound(object sender, DataListItemEv entArgs e){if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType== ListItemType.AlternatingItem){LinkButton lbtn =(LinkButton) e.Item.FindControl("lbtn delete");Ibt n. Attributes.Add("O nClick","retur n con firm‘ 确定要删除吗?‘ )");protected void DataGrid1_ItemDataBound(object sender, DataGridItemE}}}}ventArgs e){ if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem){LinkButton lbtn = (LinkButton)e.Item.Cells[3].Controls[0];lbtn.Attributes.Add("OnClick","return confirm( ‘确认删除?‘ )");}}GridView1_RowDataBound(object sender, GridViewRow EventArgs e){if(e.Row.RowType== DataControlRowType.DataRow) {stri ng strid = e.R ow.Cells[0].Text;〃猎取第一行的字段值;e.Row.Cells[3].Attributes.Add("OnClick", "return confirm ( ‘确认删除 \""+strid+"\" ?‘)");//用了两个转义符将第一列的值用引号括起来 ,注意转义符后面一个将不被讲明,是直截了当放上去 ;protected void 程序中常用的三十三种代码(1) 程序中常用的三十三种代码(2) } 双击表格打开新一页if(e.Item.ItemType == ListItemType.Item e.Item.ItemType == ListItemType. AlternatingItem){string OrderItemID =e.item.cells[1].Text;e.item.Attributes.Add("ondblclick", "open(' ../ShippedGrid.aspx?id=" + Or derItemID + " ')");}6.表格超连接列传递参数v asp:HyperLinkColumn Target="_blank" headertext二"ID号"DataTextField二"id" NavigateUrl="aaa.aspx?id='v %# DataBinder.Eval(Container.Dataltem,"数据字段1")% >' & name = v %# DataBinder.Eval(Container.Dataltem,"数据字段2")% >' />7.表格点击改变颜色if (e.Item.ItemType == ListItemType.Item e.Item.ItemType == ListItemType.AlternatingItem){ e.Item.Attributes.Add("onclick","this.style.backgroundColor= ' #99cc00' ;this.style.color=' buttontext' ;this.style.cursor=' default' ;");} 写在DataGrid 的」temDataBound 里if (e.Item.ItemType == ListItemType.Item e.Item.ItemType == ListItemType.AlternatingItem){ e.Item.Attributes.Add("onmouseover","this.style.backgroundColor=' #99cc00' ;this.style.color=' buttontext' ;this.style.cursor=' default' ;");e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='' ;this.style. color='' ;");} 8.关于日期格式日期格式设定DataFormatString="{0:yyyy-MM-dd}"我觉得应该在itembound 事件中e.items.cell["你的列”].text二DateTime.Parse(e.items.cell[‘你的列”].text.ToStrin g("yyyy-MM-dd"))9.猎取错误信息并到指定页面不要使用Response.Redirec而应该使用Server.Transfere.g// in global.asaxprotected void Application_Error(Object sender, EventArgs e) {if (Server.GetLastError() is HttpUnhandledException)Server.Transfer("MyErrorPage.aspx");//其余的非HttpUnhandledException专门交给自己处理就okay 了:)} Redirect会导致post- back的产生从而丢失了错误信息,因此页面导向应该直截了当在服务器端执行,如此就能够在错误处理页面得到出错信息并进行相应的处理10.清空Cookie<>程序中常用的三十三种代码(6) v/ASP:TEMPLATECOLUM N >v ASP:TEMPLATECOLUMN headertext二'选中” >v HEADERSTYLE wrap="False" horizontalalign="Center">v/HEADERST YLE > v ITEMTEMPLATE >v ASP:CHECKBOX id="chkExport" runat="server" />v /ITEMTEMPLATE >V EDITITEMTEMPLATE >v ASPQHECKBOX id二"chkExportON" run at二"server" en abled二"true" /> V/EDITITEMTEMPLATE >V/ASP:TEMPLATECOLUMN >后台代码protected void CheckAll_CheckedChanged(object sender, System.EventArgs e){//改变列的选定,实现全选或全不选。