一、选择题
1、下列标记不属于HTML文档的基本结构的是:( D )
A <html> B <body> C <head> D <form>
2、请问下面程序段执行完毕,页面上显示内容是什么:( A )
Response.Write (“<a href='http://www.sina.com.cn'>新浪</a>”)
A 新浪 B <a href='http://www.sina.com.cn'>新浪</a>
C 新浪 D 该句有错,无法正常输出
3、Session对象的默认有效期为多少分钟:(C )
A 10 B 15 C 20 D 应用程序从启动到结束
4、下面哪一个对象用于与数据源建立连接:( B)
A Command B Connection
C DataReader D DataAdapter
5、Global.asax文件中Session_Start事件何时激发( B )
A 在每个请求开始时激发
B 尝试对使用进行身份验证时激发
C 启动会话时激发
D 在应用程序启动时激发
6、下面哪一个文件是全局配置文件(B )
A Global.asax B Web.config
C Styles.css D AssemblyInfo.vb
7、需要写入与HTML标记相同的文本时,应利用以下何种方法进行编码:( D)
A Response.Server.(HtmlEncode (“<B>”))
B Response.Write(“Server.HtmlEncode (“<B>”)”)
C Response.Write(Server.HtmlEncode (“<B>”))
D Server.Server(Write.HtmlEncode (“<B>”))
8、下列说法正确的是(B )
A 页面上有动态的东西就是动态网页
B 静态网页内容固定,交互性能比动态网页差
C ASP、JSP和ASP.NET技术都是把脚本语言嵌入到HTML文档中
D ASP.NET程序和ASP程序一样都是解释执行
9、下面关于HTML的描述错误的是D
A 超文本标记语言,一种为Internet文档设计的标记语言
B 与操作系统平台的选择无关,只要有浏览器就可以运行HTML文档
C 所有的标记都是成对出现
D 由浏览器解释HTML标记符号并以它们指定的格式把相应的内容显示在屏幕上
10、下列关于ASP.NET的验证控件描述错误的是( A )
A 在客户端和服务器端都能进行验证
B 其客户端验证和服务器端验证对所有浏览器都适用
C 如果页面调用了多个验证控件,当有其中的一个验证未通过时,整个页面不会被通过验证
D 一个服务器控件可同时被多个验证控件验证
11、在ASP.NET应用程序中访问SqlServer数据库时,需要导入的命名空间为B
A System.Data.Oracle B System.Data. SqlClient
C System.Data. ODBC D System.Data.OleDB
12、如果需要确保用户输入大于30的值,应该使用( C )验证控件
A RequiredFieldValidator B CompareValidator
C RangeValidator D RegularExpressionValidator
13、下面哪一个不是网页文件的后缀名 (D)
A htm B aspx C asp D txt
二、填空题
1. 列举ASP.NET中的七个内置对象:(Page,Response,Request,Session,Application,Cookie, Server)
2 URL的中文意思是指.(统一资源定位符)
3 几乎所有的HTML标记都可以转化为HTML Server控件,只需要在标记中加入(.runat="server")即可
4 控件TextBox的AutoPostBack属性的作用是(是否响应服务器事件,值为true/false;)
5 Server.MapPath()方法的主要功能是(获取文件对象绝对路径)
6 Command对象ExecuteNOQuery()方法的功能是____________________
ASP.NET复习题2
一、 选择题
1. ASP.NET不支持的应用程序文件类型的扩展名是( D )
A. .ascx B. .asmx
C. .disco D. .pas
2. 下面哪一个验证控件的作用是限定用户按照一定的模式进行输入?(A )
A. RegularExpressionValidator B. CompareValidator
C. RequireFieldValidator D. ValidationSummary
3. 将已有的Web窗体页转换为用户控件时,除了要从该页中移除所有的<html>,<body>,<form>元素外,还应将原窗体页中的@page指令更改为( b )
A. Page B. @Control
C. @ascx D. Control
4. Cookie是Web服务器保存在用户硬盘上的一段文本,分会话Cookie和永久Cookie。如要定义一个永久Cookie,则必须设置Cookie的( d )属性。
A. Value B. Item
C. Path D. Expires
5. 要获取Web站点中某个文件的物理存储路径,可以使用Server对象的( b )属性。
A. Execute B. MapPath
C. Transfer D. HtmlEncode
6. Response对象的( b )方法可以使Web服务器停止处理脚本。
A. Clear B. End
C. BufferOutput D. Flush
7. 访问DataReader对象中的某列可以采用如DataReader(“Name”)的方法。该示例默认使用的是DataReader对象的(c )属性。
A. IsClosed B. FieldCount 字段数
C. Item D. RecordsAffected
8. 在绑定了数据源的Repeater对象中,系统会自动提供( b )对象,可以使用该对象的Eval方法从指定的列中检索数据。
A. Container B. DataBinder
C. DataReader D. DataTable
9. 在DataList控件中,任何一个按钮单击时,都会触发( b )事件。
A. EditCommand B. ItemCommand
C. CancelCommand D. SelectCommand
10. 要将存储过程参数@Name设定为输出参数 ,则应该设定SqlParameter对象的( a )属性。
A. Direction B. SqlDbType
C. Value D. Size
11. 在使用DataView对象进行筛选和排序等操作之前,必须指定一个( a )对象作为DataView对象的数据来源。
A. DataTable B. DataGrid
C. DataRows D. DataSet
12. 在包含多个表的DataTable对象的DataSet中,可以使用( a )对象来使一个表和另一个表相关。
A. DataRelation B. Collections
C. DataColumn D. DataRows
13. DataGrid控件使用( a )列来指定要显示数据源中的那些列、自定义每列的标头和脚注以及控件的排序等。
A. 绑定列 B. 按钮列
C. 超级链接列 D. 模板列
14. 在DataGrid控件中设定显示学生的学号,姓名,出生日期等字段。现要将出生日期设定为短日期格式,则应将数据格式表达式设定为(a )。
A. {0:d} B. {0:c}
C. {0:yy-mm-dd} D. {0:p}
15. Web Service公开的每个方法,必须用自定义的( c )属性进行标记。
A. NameSpace B. Class
C. WebMethod D. Description
二、程序填空题
本题将创建一个简单的学生管理信息系统,包含用户登陆页面(Login.aspx)和学籍管理页面(Student.aspx)。假设已经建好数据库StudentMS。请按要求补全程序。
1、创建用户登陆页面(Login.aspx)
(1)添加web窗体,命名为Login.aspx ,该页面的设计布局如下:
(2) 分别将两个TextBox控件和Button控件的ID设置为:txtName, txtPassword, btnSubmit;分别为两个TextBox控件添加RequiredFieldValidator验证控件,限制用户必须输入用户名和密码;在Web.config中定义对数据库访问的连接字符串;导入相应的命名空间。
(3) 定义私有过程,实现将用户的登陆名保存到Cookie中。代码如下:
Private Sub AddLoginNameToCookie(ByVal strLoginName As String)
Dim MyCookie As New HttpCookie("StudentMS")
MyCookie.Expires = DateTime.Now.AddDays(30)
MyCookie.Values.Add("LoginName", strLoginName)
Response.Cookies.Add(MyCookie) ‘将MyCookie添加到Cookies集合
End Sub
(4) 定义私有函数,实现从Cookie中获取用户的登陆名返回给调用者。代码如下:
Private Function GetLoginNameFromCookie() As String
Dim MyCookie As HttpCookie = Request.Cookies("StudentMS")
Dim strLoginName As String = ""
If Not MyCookies Is Noting Then ‘cookie值不为空
strLoginName = MyCookie.Values("LoginName")
Return strLoginName
End If
End Function
(5) 向btnSubmit_Click事件中添加代码,使程序可以从数据库中检索到用户的登陆信息并判断用户的合法性。
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If Page.IsValid Then ‘页面验证成功
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("DBConnStr"))
Dim strSQL As String = "select UserID,Password,UserType from tblUsers where LoginName='" & Trim(txtName.Text) & "'"
Dim cmd As New SqlCommand(strSQL, conn)
Dim objReader As SqlDataReader
Try
conn.Open()
objReader = cmd.ExecuteReader
If objReader.Read Then
If obgReader(1)=Trim(txtPassword.Text) Then ‘用户密码正确
‘定义session变量保存用户名称
Session("UserName") = Trim(txtName.Text)
AddLoginNameToCookie(Trim(txtName.Text))
Response.Redirect("Student.aspx")
Else
lblMessage.Text = "密码错误,请重新输入!"
End If
Else
lblMessage.Text = "用户名不存在"
End If
objReader.Close() ‘关闭数据读取器
Catch ex As Exception
lblMessage.Text = ex.Message
Finally
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Try
End If
End Sub
(6) 为Web窗体的Page_Load事件编写代码,实现页面初次加载读取Cookies功能。
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Not Me.IsPostBack Then
txtName.Text=GetLoginNameFromCookies() ‘将获取的Cookies显示在用户名栏内
End If
End Sub
2. 创建学籍管理页面 (Student.aspx)
(1) Student.aspx页面的设计布局如下图:
设定下拉列表框的ID为lstClasses,按钮的ID为btnSubmit,DataGrid控件的ID为grdStudents,其DataKeyField属性设置为StudentID。使用属性生成器添加相应绑定列,并将学号设定为只读;添加编辑与删除两个按钮列。
(2) 导入相应命名空间,定义全局变量,代码如下:
Private strSQL = "select * from tblStudents"
Private conn As New_ SqlConnection(ConfigurationSettings.AppSettings("DBConnStr"))
Private da As New SqlDataAdapter(strSQL, conn)
Private ds As New DataSet
(2) 添加自定义过程FillDropDownList(),实现用班级信息填充下拉列表框的功能。
Private Sub FillDropDownList()
Dim objCmd As SqlCommand
strSQL = "select distinct Class from tblStudents order by Class"
objCmd = New SqlCommand(strSQL, conn)
conn.Open()
lstClasses.DataSource = objCmd.ExecuteReader
lstClasses.DataTextField=”Class” ‘将班级字段付给下拉类别DataTextField属性
lstClasses.DataBind()
conn.Close()
lstClasses.Items.Add("所有班级")
lstClasses.SelectedIndex = lstClasses.Items.Count - 1
End Sub
(3) 添加自定义过程LoadGrid(),实现根据选定班级加载数据到DataGrid控件的功能。
Private Sub LoadGrid()
da.Fill(ds, "Students")
Dim dv As New DataView( ds.Table(“Students”) )‘用Students表初始化dv
Dim strClass As String = lstClasses.SelectedItem.Value.Trim
If strClass <> "所有班级" Then
dv.RowFilter = "Class='" & strClass & "'" ‘利用dv视图筛选班级
End If
grdStudents.DataSource = dv
grdStudents.DataBind()
End Sub
(4) 为Web窗体的Page_Load事件编写代码,实现的功能为:使未经登陆的用户重定向到登陆页面;调用FillDropDownList()过程以显示班级列表;调用LoadGrid()过程以加载数据到DataGrid
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
If Session("UserName") Is Nothing Then ‘用户未登陆
Response.Redirect("Login.aspx")
Else
If Not Me.IsPostBack Then
FillDropDownList()
LoadGrid()
End If
End If
End Sub
(5) 在btnSubmit_Click实践中调用LoadGrid()过程。
(6) 为DataGrid控件的编辑按钮添加代码,分别实现编辑、取消、更新的功能。
Private Sub grdStudents_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdStudents.EditCommand
grdStudents.EditItemIndex = e.Item.ItemIndex
LoadGrid()
End Sub
Private Sub grdStudents_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdStudents.CancelCommand
grdStudents.EditItemIndex = -1
LoadGrid()
End Sub
(7) 为DataGrid控件的删除按钮添加代码,实现删除记录的功能。
Private Sub grdStudents_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdStudents.DeleteCommand
Dim cmd As SqlCommand
Dim orgID As String = Students.DataKeys(e.Item.ItemIndex) ‘用DataKeys集合获取学生学号
Dim strDelete As String = "delete from tblStudents where StudentID='" & orgID & "'"
conn.Open()
cmd = New SqlCommand(strDelete, conn)
cmd.ExecuteNonQuery() ‘执行Command对象
conn.Close()
grdStudents.EditItemIndex = -1
LoadGrid()
End Sub
(8) 为DataGrid控件中记录分页,编写PageIndexChanged事件过程。
Private Sub grdStudents_ (ByVal source As Object, ByVal e As_ System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles grdStudents.PageIndexChanged
grdStudents.CurrentPageIndex = e.NewPageIndex
LoadGrid()
End Sub
参考答案:
一、单选题
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 1 | 11 | 12 | 13 | 14 | 15 |
D | A | B | D | B | B | C | B | B | A | A | A | A | A | C |
2、 程序填空题
1) Response.Cookies.Add(MyCookie)
2) Not MyCookie Is Nothing
3) Page.IsValid
4) objReader(1) = Trim(txtPassword.Text)
5) objReader.Close()
6) txtName.Text = GetLoginNameFromCookie()
7) lstClasses.DataTextField = "Class"
8) ds.Tables("Students")
9) dv.RowFilter = "Class='" & strClass & "'"
10) Session("UserName") Is Nothing
11) grdStudents.EditItemIndex = e.Item.ItemIndex
12) grdStudents.EditItemIndex = -1
13) Students.DataKeys(e.Item.ItemIndex)
14) cmd.ExecuteNonQuery()
15) grdStudents.CurrentPageIndex = e.NewPageIndex
三、简答题
1. DataSet对象有哪些特点?
内存中的数据库 ;数据源独立性 ;断开式连接 ;使用XML格式
2. 什么是存储过程?使用存储过程有什么好处?
存储过程是一些SQL语句和控制语句的集合,它有一个名称,并经过预编译作为一个独立的单元存储在数据库内。
(1) 存储过程执行起来比SQL命令文本快得多。
(2) 为应用程序提供更大的灵活性
(3) 可以在存储过程中利用Transact-SQL的强大功能。
(4) 减少网络数据量
(5) 模块化
(6) 增强数据库的安全性
3. 什么是Web Service? 组成Web Service的两个角色是什么?
Web Service即Web服务,是通过Internet协议公开的一种业务功能,它提供接口或服务,供外界使用。组成Web Service的两个角色分别是Web Service提供程序和Web Service客户端。
4. 什么是XCOPY部署? 使用XCOPY方式部署一个ASP.net应用程序有那几个主要步骤?
XCOPY部署是一种部署ASP.NET应用程序的一种方法,其典型的做法是:本地复制时使用Windows资源管理器;远程部署时使用FTP。主要分三步:在IIS中的把目标文件夹配置为Web应用程序目录; 生成应用程序并选择所有必要的文件; 复制或者使用FTP上传必要文件
5. 如何在Web.config文件中保存连接字符串,如何在程序中访问该字符串?(假设访问SQL Server远程服务器 MyServer 的 StudentMS数据库,用户名/密码为:sa/123)
<appSettings>
<add key="DBConnStr" value="Server=MyServer;Database=StudentMS;User ID=sa;Password=123"/>
</appSettings>
在程序中访问:ConfigurationSettings.AppSettings("DBConnstr")
6. ASP.net中的身份验证包含哪几种类型?
包含窗体身份验证;Passport(护照)身份验证; Windows身份验证3种类型
7. ADO.NET中包含那些对象?
包含Connection, Command, DataReader, DataAdapter, DataSet
8. 简述可以采用哪几种方法将HTML标记转换为Web服务器控件?
两种:在html代码中为HTML元素添加runat=’server’属性;右键单击,选择作为服务器控件运行。
9. 如何在VS.NET2003中浏览一个Web页面?
可以采用3种方式:Web浏览器的地址栏中输入当前网页地址,如http://LocalHost/StuMS/Login.aspx;在VS 的资源管理器中右键点击选择在浏览器中查看; 在VS 的资源管理器中将该页设为起始页,启动项目。
10. 发现文档的作用是什么?有几种类型?
发现文档用于对Web服务器上的公共Web Service进行分组。发现文档是基于XML的文件,该文件包含资源的URL链接,该资源为Web Service提供发现信息。可分为静态发现和动态发现。
11. DataReader对象有哪些特点?
只能读取数据,不能对数据进行编辑、添加和删除;只能在记录间向前移动; 不能在IIS内存中存储数据,数据直接在显示对象上显示; 工作在连接模式下
12. 什么是Web Service? 组成Web Service的两个角色是什么?
Web Service即Web服务,是通过Internet协议公开的一种业务功能,它提供接口或服务,供外界使用。组成Web Service的两个角色分别是Web Service提供程序和Web Service客户端。
13. Application和Session对象的事件分别在什么时候发生?它们在使用时需要实例化么?为什么?
分别是在应用程序启动时和会话启动时发生的。不需要实例化,因为它们都是page对象的成员。
14. ASP.NET的关键技术有哪些?
事件驱动;代码隐藏技术;数据绑定技术;数据访问技术ADO.NET;面向对象特性;多语言支持
15. 试列举出常用的服务器端数据验证控件(不低于4个)
RequiredFieldValidator(必须项);CompareValidator(与某值的比较);RangeValidator(范围检查);RegularExpressionValidator(模式匹配);CustomValidator(用户定义);ValidationSummary
16. Web窗体页面有哪两种布局模式?特点分别是什么?
流布局和网格布局。网格布局用于精确定位元素;流布局用于象处理文字一样处理元素,元素在一行内从左向右流动,在页面上从上到下流动,
17. 在ADO.NET中调用存储过程与执行SQL命令文本的方法区别在什么地方?
调用存储过程,Command对象的CommandText属性为存储过程名, CommandType属性为CommandType.StoredProcedure;执行SQL命令文本时,Command对象的CommandText属性为具体的SQL语句, CommandType属性为CommandType.Text
18. 简述创建一个DataRelation对象的过程。
为父列声明一个DataColulmn对象,并指出那个列作为父列;为子列声明一个DataColulmn对象,并指出那个列作为子列;创建DataRelation对象,并为关系,父列和子列指定名称;将DataRelation对象添加到DataSet集合中。