网页设计Web常用控件Word格式文档下载.docx
《网页设计Web常用控件Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《网页设计Web常用控件Word格式文档下载.docx(22页珍藏版)》请在冰豆网上搜索。
(5)调试运行
实验步骤
一、使用选择性控件(下拉列表框和复选框)设计一个能根据用户选择查询员工信息的Web应用程序。
1、设计Web页面以及对象属性,得到如下界面:
2、编写事件代码:
页面装入时执行在事件代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
publicpartialclass_Default:
System.Web.UI.Page
{
structInfo
{
publicstringName;
publicstringSex;
publicstringBirthday;
publicstringAddress;
publicstringPhone;
publicstringEducation;
}
Info[,]Employloy=newInfo[3,3];
protectedvoidPage_Load(objectsender,EventArgse)
this.Title="
选择控件应用事例"
;
Employloy[0,0].Name="
张三"
Employloy[0,0].Sex="
男"
Employloy[0,0].Birthday="
1982-4-6"
Employloy[0,0].Address="
1号楼"
Employloy[0,0].Phone="
1234567"
Employloy[0,0].Education="
本科"
Employloy[0,1].Name="
李四"
Employloy[0,1].Sex="
女"
Employloy[0,1].Birthday="
1983-12-26"
Employloy[0,1].Address="
2号楼"
Employloy[0,1].Phone="
2345678"
Employloy[0,1].Education="
Employloy[0,2].Name="
李好"
Employloy[0,2].Sex="
Employloy[0,2].Birthday="
Employloy[0,2].Address="
Employloy[0,2].Phone="
Employloy[0,2].Education="
Employloy[1,0].Name="
赵六"
Employloy[1,0].Sex="
Employloy[1,0].Birthday="
1980-1-30"
Employloy[1,0].Address="
Employloy[1,0].Phone="
4567890"
Employloy[1,0].Education="
高中"
Employloy[1,1].Name="
陈七"
Employloy[1,1].Sex="
Employloy[1,1].Birthday="
1983-2-26"
Employloy[1,1].Address="
Employloy[1,1].Phone="
5678901"
Employloy[1,1].Education="
专科"
Employloy[1,2].Name="
陈美"
Employloy[1,2].Sex="
Employloy[1,2].Birthday="
Employloy[1,2].Address="
Employloy[1,2].Phone="
Employloy[1,2].Education="
Employloy[2,0].Name="
何南"
Employloy[2,0].Sex="
Employloy[2,0].Birthday="
1981-3-6"
Employloy[2,0].Address="
Employloy[2,0].Phone="
7890123"
Employloy[2,0].Education="
Employloy[2,1].Name="
贺北"
Employloy[2,1].Sex="
Employloy[2,1].Birthday="
1983-10-1"
Employloy[2,1].Address="
Employloy[2,1].Phone="
8901234"
Employloy[2,1].Education="
Employloy[2,2].Name="
贺男"
Employloy[2,2].Sex="
Employloy[2,2].Birthday="
Employloy[2,2].Address="
Employloy[2,2].Phone="
Employloy[2,2].Education="
if(DropUnit.Text=="
-选择部门-"
)
DropName.Items.Clear();
DropName.Items.Add("
-选择姓名-"
);
DropName.Text="
}
protectedvoidDropUnit_SelectedIndexChanged(objectsender,EventArgse)
inti=0,j=0;
switch(DropUnit.Text)
case"
教务处"
:
i=0;
break;
学生处"
i=1;
科研处"
i=2;
if(DropUnit.Text=="
return;
DropName.Items.Clear();
for(j=0;
j<
3;
j++)
DropName.Items.Add(Employloy[i,j].Name);
DropName.Items.Add("
DropName.Text="
protectedvoidDropName_SelectedIndexChanged(objectsender,EventArgse)
if(DropName.Text=="
inti=0,j=0;
switch(DropUnit.Text)
i=0;
i=1;
i=2;
for(j=0;
j<
3;
j++)
if(DropName.Text==Employloy[i,j].Name)
PlaceHolder1.Controls.Clear();
TableTab=newTable();
Tab.GridLines=GridLines.Both;
Tab.CellPadding=1;
Tab.CellSpacing=3;
Tab.Width=450;
PlaceHolder1.Controls.Add(Tab);
TableRowMyRow=newTableRow();
TableCellMyCell0=newTableCell();
MyCell0.Text="
<
b>
姓名<
/b>
"
MyRow.Cells.Add(MyCell0);
TableCellMyCell1=newTableCell();
MyCell1.Text=Employloy[i,j].Name;
MyRow.Cells.Add(MyCell1);
TableCellMyCell2=newTableCell();
MyCell2.Text="
性别<
MyRow.Cells.Add(MyCell2);
TableCellMyCell3=newTableCell();
MyCell3.Text=Employloy[i,j].Sex;
MyRow.Cells.Add(MyCell3);
TableCellMyCell4=newTableCell();
MyCell4.Text="
生日<
MyRow.Cells.Add(MyCell4);
TableCellMyCell5=newTableCell();
MyCell5.Text=Employloy[i,j].Birthday;
MyRow.Cells.Add(MyCell5);
Tab.Rows.Add(MyRow);
TableRowMyRow1=newTableRow();
if(CheckDisplay.Items[0].Selected)
TableCellMyCell6=newTableCell();
MyCell6.Text="
住址<
MyRow1.Cells.Add(MyCell6);
TableCellMyCell7=newTableCell();
MyCell7.Text=Employloy[i,j].Address;
MyRow1.Cells.Add(MyCell7);
if(CheckDisplay.Items[1].Selected)//若“电话”复选框处于被选中状态
TableCellMyCell8=newTableCell();
MyCell8.Text="
电话<
MyRow1.Cells.Add(MyCell8);
TableCellMyCell9=newTableCell();
MyCell9.Text=Employloy[i,j].Phone;
MyRow1.Cells.Add(MyCell9);
if(CheckDisplay.Items[2].Selected)//若“学历”复选框处于被选中状态
TableCellMyCell10=newTableCell();
MyCell10.Text="
学历<
MyRow1.Cells.Add(MyCell10);
TableCellMyCell11=newTableCell();
MyCell11.Text=Employloy[i,j].Education;
MyRow1.Cells.Add(MyCell11);
Tab.Rows.Add(MyRow1);
//添加一个新行
protectedvoidCheckDisplay_SelectedIndexChanged(objectsender,EventArgse)
if(DropName.Text==Employloy[i,j].Name)
break;
3、调试,界面如下:
二、使用向页面中动态添加控件的技术,设计一个简易的在线测验web应用程序。
string[,]Answer=newstring[2,5];
Label[]LabelTitle=newLabel[4];
RadioButtonList[]RadioList=newRadioButtonList[2];
this.Title="
向页面中动态添加控件"
Answer[0,0]="
美国"
Answer[0,1]="
英国"
Answer[0,2]="
法国"
Answer[0,3]="
日本"
Answer[0,4]="
3"
Answer[1,0]="
东京"
Answer[1,1]="
伦敦"
Answer[1,2]="
华盛顿"
Answer[1,3]="
旧金山"
Answer[1,4]="
2"
string[]Question=newstring[2];
Question[0]="
距离我国最近的国家是:
Question[1]="
美国的首都是:
LabelLabel0=newLabel();
LabelLabel1=newLabel();
LabelLabel2=newLabel();
LabelLabel3=newLabel();
Label2.Text="
hr>
Label3.Text="
LabelTitle[0]=Label0;
LabelTitle[1]=Label1;
LabelTitle[2]=Label2;
LabelTitle[3]=Label3;
RadioButtonListRadio0=newRadioButtonList();
RadioButtonListRadio1=newRadioButtonList();
RadioList[0]=Radio0;
RadioList[1]=Radio1;
for(inti=0;
i<
2;
i++)
intNum=i+1;
LabelTitle[i].Text=Num.ToString()+"
."
+Question[i];
RadioList[i].RepeatDirection=RepeatDirection.Horizontal;
for(intj=0;
4;
RadioList[i].Items.Add(Answer[i,j]);
PlaceHolder1.Controls.Add(LabelTitle[0]);
PlaceHolder1.Controls.Add(RadioList[0]);
PlaceHolder1.Controls.Add(LabelTitle[2]);
PlaceHolder2.Controls.Add(LabelTitle[1]);
PlaceHolder2.Controls.Add(RadioList[1]);
PlaceHolder2.Controls.Add(LabelTitle[3]);
protectedvoidButtonSubmit_Click(objectsender,EventArgse)
intSum=0;
LabelTitle[i].BackColor=System.Drawing.Color.White;
if(RadioList[i].SelectedIndex==int.Parse(Answer[i,4]))