2024年1月4日发(作者:)
Chap01参考答案
一、填空题
1、Web XML Web services
2、公共语言运行库、.NET Framework类库
3、属性 方法 事件
4、aspx
5、cs
二、选择题
1、ABCD 2、ABCD 3、AB 4、A 5、B
三、上机操作题
1、参考1.3.1。
2、参考1.4.2。
3、在ex1_文件中的代码如下所示:
在ex1_中的代码如下所示:
public partial class _Default :
{
private static int i;
protected void Page_Load(object sender, EventArgs e)
{
if(!Back)
i = 0;
}
protected void Button1_Click(object sender, EventArgs e)
{
i=i+1;
= "您单击了"+ng()+"次按钮";
}
}
Chap02参考答案
一、填空题
1、引用类型
2、object
3、显式
4、多态性
5、初始化语句右侧
二、选择题
钮"
1、AC 2、A 3、B 4、B 5、AC
三、上机操作题
1、本习题的源代码如下:
namespace ex2_1
{
struct student
{
public string name;
public string address;
public string tel;
};
class Program
{
static void Main(string[] args)
{
student[] stu = new student[5];
for (int i = 0; i < 5; i++)
{
stu[i].name = ne();
stu[i].address = ne();
stu[i].tel = ne();
}
for (int i = 0; i < 5; i++)
{
ine(ng());
ine(stu[i].name);
ine(stu[i].address);
ine(stu[i].tel);
}
ne();
}
}
}
2、本习题的源代码如下:
namespace ex2_2
{
class Program
{
static void sort(int[] a, int n)
{
int temp;
for (int i = 1; i < n; i++)
for (int j = 0; j < n - i; j++)
if (a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
static void Main(string[] args)
{
int n = 5;
int[] a = new int[5];
for (int i = 0; i < 5; i++)
{
a[i] = 32(ne());
}
sort(a, n);
for (int i = 0; i < 5; i++)
{
ine(a[i].ToString());
}
ne();
}
}
}
3、本习题的源代码如下:
namespace ex2_3
{
class student
{
protected string m_name;
protected string m_sex;
protected float m_tuition;
public student(string strname, string strsex, float ftuition)
{
m_name = strname;
m_sex = strsex;
m_tuition = ftuition;
}
virtual public void printfInfo()
{
ine(m_name + " " + m_sex + " " + m_ng());
}
}
class graduate : student
{
protected string m_tutor;
public graduate(string strname,
strtutor):base(strname,strsex,ftuition)
{
m_tutor = strtutor;
}
override public void printfInfo()
{
Info();
ine("导师是"+m_tutor);
}
}
class Program
{
static void Main(string[] args)
{
string strsex, float ftuition,string
student s = new student("张三", "男", 5000);
graduate g = new graduate("李四", "女", 9000, "王五");
Info();
Info();
ne();
}
}
}
Chap03参考答案
一、填空题
1、HttpResponse
2、客户端
3、服务器
4、状态变量
5、用户会话
二、选择题
1、C 2、ABCD 3、ABCD 4、AD
三、上机操作题
1、在ex_1_文件中的代码如下所示:
在ex_1_文件中的代码如下所示:
public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ct("ex_1_?name=张三");
}
}
在ex_1_文件中的代码如下所示:
public partial class ex_1_2 :
{
protected void Page_Load(object sender, EventArgs e)
{
(tring["name"]);
}
}
2、在ex2_文件中的代码如下所示:
在ex_2_文件中的代码如下所示:
public partial class __ex_2_1 :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = "李四";
ct("ex_2_");
}
}
在ex_2_文件中的代码如下所示:
在ex_2_文件中的代码如下所示:
public partial class _ex_2_2 :
{
protected void Page_Load(object sender, EventArgs e)
{
= Session["name"].ToString();
}
}
3、在ex_3_文件中的代码如下所示:
public partial class _ex_3_1 :
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie cookie1 = s["ttt"];
if (cookie1 == null)
{
//创建一个cookie实例
HttpCookie cookie = new HttpCookie("ttt");
//添加要存储的信息,采用键/值结合的方式
("Name", "Tom");
s = rs(1);
//把cookie加如当前的页面的Response对象里面
(cookie);
ct("");
}
else
{
(["Name"]);
}
}
}
Chap04参考答案
一、填空题
1、trols
2.设置是否自动向服务器发送数据 false
用户单击此控件时并不导致向服务器发送页面。
3.编程方式 运行时更改页面中的文本
4.标头 标题 链接 链接
5.图像 作用点控件的集合
二、1.D 2.B 3.D 4.C 5.D
三、上机操作题
1、在ex4_文件中代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="ex4_1" %>
"/TR/xhtml1/DTD/">
CodeFile="ex4_"
1.0 Transitional//EN"
ex4_的代码如下所示:
public partial class ex4_1 :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DisplayType(object sender, EventArgs e)
{
= ;
}
}
2、在ex4_文件中代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ex4_"
Inherits="ex4_2" %>
"/TR/xhtml1/DTD/">
ex4_的代码如下所示:
public partial class ex4_2 :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (!rMonth && !end)
lor = ;
else if (!rMonth && end)
{
lor = ;
ctable = false;
}
}
}
3、在ex4_文件中代码如下所示:
在ex4_文件中代码如下所示:
public partial class ex4_3 :
{
protected void Page_Load(object sender, EventArgs e)
{
}
BulletStyle="Disc"
protected void ItemsBulletedList_Click(object sender, BulletedListEventArgs e)
{
switch ()
{
case 0:
= "百度";
break;
case 1:
= "谷歌";
break;
case 2:
= "新浪";
break;
}
}
}
Chap05参考答案
一、填空题
1、客户端数据验证 服务器端数据验证
2、RequiredFieldValidator
3、CompareValidator
4、RegularExpressionValidator
5、.ascx
二、1.D 2. D 4、C 5、AB
三、上机操作题
1、ex5_的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="ex5_1" %>
"/TR/xhtml1/DTD/">
CodeFile="ex5_"
1.0 Transitional//EN"
2、ex5_的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ex5_"
Inherits="ex5_2" %>
"/TR/xhtml1/DTD/">
3、身份验证用户控件的源代码如下:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile=""
Inherits="IDValidate" %>
ControlToValidate="TextBox1" ErrorMessage="您输入的身份证号码有误,请重新输入!" ValidationExpression="d{17}[d|X]|d{15}">
ex5_的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ex5_"
Inherits="ex5_3" %>
<%@ Register src="" tagname="IDValidate" tagprefix="uc1" %>
"/TR/xhtml1/DTD/">
Chap06 参考答案
一、1.Connection Command DataSetCommand DataSet DataReader
2.数据处理 Connection Command DataReader DataAdapter
3.User ID(uid) Password(pwd) 用户ID 口令
4.SqlDataSource ACCESS 密码 ACCESS
5.数据命令 数据库连接 填充 DataSet 更新数据源 DataSet
二、1.B 3.A 4.A
三、上机操作题
1、ex6_的源代码如下:
protected void Page_Load(object sender, EventArgs e)
{
String sqlconn = " Provider=.4.0;Data
Source=E:";
OleDbConnection myConnection = new OleDbConnection(sqlconn);
();
OleDbCommand myCommand = new OleDbCommand("select * from Book", myConnection);
OleDbDataReader myReader;
myReader = eReader();
("
使用OleDbCommand类读取数据
");
("
| " + e(i) + " | ");
| " + myReader[i].ToString() + " | ");
();
();
}
2、ex6_的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="ex6_2" %>
"/TR/xhtml1/DTD/">
Ex6_的主要代码如下:
protected void Page_Load(object sender, EventArgs e)
{
string ConnectionStr = " Provider=.4.0;Data Source=
E: ";
OleDbConnection myConn = new OleDbConnection(ConnectionStr);
();
OleDbCommand myCommand = new OleDbCommand("select * from Book", myConn);
OleDbDataAdapter Adapter = new OleDbDataAdapter();
Command = myCommand;
DataSet myDs = new DataSet();
(myDs);
urce = [0].DefaultView;
nd();
();
}
3、ex6_的主要代码如下:
public partial class ex6_3 :
{
void CreateXmlDocument(string file)
{
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDeclaration = XmlDeclaration("1.0", "utf-8", null);
Before(xmlDeclaration, ntElement);
XmlElement rootNode = Element("books");
Child(rootNode);
{
XmlElement parentNode = Element("book");
XmlElement title = Element("title");
XmlText strTitle = TextNode("入门");
Child(strTitle);
Child(title);
XmlElement author = Element("author");
XmlText txtAuth = TextNode("张三");
Child(txtAuth);
Child(author);
dChild(parentNode);
}
{
XmlElement parentNode = Element("book");
XmlElement title = Element("title");
XmlText strTitle = TextNode("精通");
Child(strTitle);
Child(title);
XmlElement author = Element("author");
XmlText txtAuth = TextNode("李四");
Child(txtAuth);
Child(author);
dChild(parentNode);
}
(h(file));
}
void ReadXmlFile(string file)
{
//获得文件的物理路径
string xml = h(file);
XmlDocument doc = new XmlDocument();
(xml);
XmlNodeList elemList1 = mentsByTagName("books");
for (int i = 0; i < ; i++)
{
XmlNode book = elemList1[i];
for (int j = 0; j < ; j++)
{
XmlNode node = odes[j];
("
名称:" + odes[0].InnerText);
("
作者:" + odes[1].InnerText);
("
");}
}
}
protected void Page_Load(object sender, EventArgs e)
{
("
开始创建XML文档
");
CreateXmlDocument("");
("成功创建Xml文档!");
("
读取文件
");
ReadXmlFile("");
}
}
Chap07参考答案
一、填空题
1. 特定数据源 网页上的其他控件
2. Microsoft SQL Server OLE DB ODBC Oracle
3. Microsoft Access
4. 数据检索 更新功能 高级排序 分页操作
5. 模板
二、选择题
4、A 5、C
三、上机操作题
7_的源代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="ex7_1" %>
"/TR/xhtml1/DTD/">
CodeFile="ex7_"
1.0 Transitional//EN"
7_的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true"
Inherits="ex7_2" %>
"/TR/xhtml1/DTD/">
CodeFile="ex7_"
1.0 Transitional//EN"
除了网页中的代码外,我们还需要在DropDownList控件的SelectedIndexChanged事件中加入如下代码:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
nd();
}
7_文件的源代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ex7_"
Inherits="ex7_3" %>
"/TR/xhtml1/DTD/">
Chap08参考答案
一、填空题
1. 关键字 运算符
2. from select group
3. SQL XQuery 查询表达式 包含查询表达式
4. 数据库数据 数据源类 内存中集合
5. 内存XML
二、选择题
2.C 3.D 4、BD 5、AC
三、上机操作题
8_的源代码如下所示:
namespace ex8_1
{
class Program
{
static void Main(string[] args)
{
int[] scores = { 90, 71, 82, 93, 75, 82 };
IEnumerable
from score in scores
where score > 80
orderby score descending
select score;
ine("大于80的成绩有:");
foreach (int testScore in scoreQuery)
{
ine(testScore);
}
ne();
}
}
}
8_的源代码如下所示:
public partial class ex8_2 :
{
protected void Page_Load(object sender, EventArgs e)
{
String path = h(".App_");
String sqlconn = " Provider=.4.0;Data Source=" + path;
OleDbConnection myConn = new OleDbConnection(sqlconn);
();
OleDbCommand myCommand = new OleDbCommand("select * from Book", myConn);
OleDbDataAdapter Adapter = new OleDbDataAdapter();
Command = myCommand;
DataSet myDs = new DataSet();
(myDs);
DataTable book = [0];
var query =
from w in erable()
select new
{
名称 =
价格 =
};
urce = query;
nd();
();
}
}
8_的源代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ex8_"
Inherits="ex8_3" %>
"/TR/xhtml1/DTD/">
ex8_的源代码如下所示。
public partial class ex8_3 :
{
protected void Button1_Click(object sender, EventArgs e)
{
string xml = h(".App_");
XElement root = (xml);
rable
from el in ts("book")
where (string)ute("ISBN") ==
select el;
foreach (XElement el in address)
{
ute("title").Value = ;
ute("price").Value = ;
}
(xml);
}
}
Chap09参考答案
一、填空题
1. ContentPlaceHolder ContentPlaceHolder 内容页
2. 公共成员 控件
3. 站点地图 控件 代码
4. 其他站点地图提供程序 其他站点地图文件
该站点的其他目录 同一应用程序中的其他站点。
二、选择题
1.C 2.A 4、A 5、C
三、上机操作题
的源代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile=""
Inherits="_Default" %>
"/TR/xhtml1/DTD/">
的源代码如下所示:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile=""
Inherits="_Default" %>
"/TR/xhtml1/DTD/">
3.母版页MasterPage_的源代码如下:
public partial class MasterPage_Load : Page
{
protected void Page_Load(object sender, EventArgs e)
{
("");
}
}
内容页Home_的源代码如下:
public partial class Home_Load :
{
protected void Page_Load(object sender, EventArgs e)
{
("");
}
}
Chap10参考答案
一、填空题
1、HTTP
2、XML
3、XML
4、信息注册
5、交互
二、选择题
1、ABC 2、ABCD 3、ABC 4、ABCD 5、ABCD
三、上机操作题
1、在文件中的代码如下:
[WebService(Namespace = "/")]
[WebServiceBinding(ConformsTo = rofile1_1)]
public class Service : vice
{
public Service () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public int add(int a,int b) {
return a + b;
}
}
2、在文件中的代码如下:
在文件中的代码如下:
public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
e ws = new e();
= (32(),
32()).ToString();
}
}
3、在文件中加入如下代码:
[WebMethod]
public bool GetBook(out DataSet ds)
{
String sqlconn = " Provider=.4.0;Data Source=E:3.5动态网站开发基础教程代码chap10ExServiceExApp_;";
OleDbConnection myConnection = new OleDbConnection(sqlconn);
();
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Book", myConnection);
ds = new DataSet();
(ds);
return true;
}
在该网站中添加一个名为的文件,在该文件中加入一个GridView控件,然后在的Page_Load函数中加入如下代码:
protected void Page_Load(object sender, EventArgs e)
{
e svr = new e();
DataSet ds = new DataSet();
if(k(out ds))
{
urce = ds;
nd();
}
}
Chap11参考答案
一.填空题
1.
2. Name LoginUrl Protection TimeOut
3. Session_Start Session n
4. HttpApplication Application_Start
Application_EndRequest Application_End
二、选择题
1. ABCD 3.D 4. AD
Application_BeginRequest
三、上机实习题
里面连接信息的内容为:
的内容为:
public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration rootWebConfig = bConfiguration("~/"); ;
ConnectionStringSettings connString;
if (0 < )
{
connString = tionStrings[1];
if (tionString != "")
{
OleDbConnection myConnection = new OleDbConnection(tionString);
();
OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from Book", myConnection);
DataSet ds = new DataSet();
(ds);
urce = new DataView([0]);
nd();
}
}
}
}
2. 的代码为:
public partial class ChooseAuthor :
{
protected void Page_Load(object sender, EventArgs e)
{
= Application["works"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["author"] = ;
ct("");
}
}
的代码为:
public partial class DisplayWorks :
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration rootWebConfig = bConfiguration("~/"); ;
//声明ConnectionStringSettings对象
ConnectionStringSettings connString;
//如果连接字符串大于0则继续查找连接信息,否则返回Nothing
if (0 < )
{
= Session["author"].ToString();
connString = tionStrings[1];
//得到连接信息
if (tionString != "")
{
SqlConnection myConnection = new SqlConnection(tionString);
();
string strSel = "select * from works Where 作者 = '" + Session["author"] + "'";
SqlDataAdapter myCommand = new SqlDataAdapter(strSel, myConnection);
DataSet ds = new DataSet();
(ds);
urce = new DataView([0]);
nd();
}
}


发布评论