C#网页控件课程设计论文

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《C#网络编程技术》综合实验报告三
题目:
B/S 控件应用
院(系): 专业班级: 学 号:
学生姓名: 指导教师: 教师职称: 起止时间:
B/S 控件应用 一、问题描述 本课程设计的目的是锻炼学生熟练掌握简单的 C#窗体和控件的设计。 使之能够应用 Visual Studio 程序软件熟练进行 web 窗体小项目的编辑。希望通过本次练习提高学生 使用 C#语言控件解决实际问题的能力。 二、问题分析 1、需要实现的系统目标 a)通过 Visual Studio 程序软件,结合所学内容,进行 C#程序 web 控件的编写; b)所有控件最终设计要达成之前预计实现的各项功能; c)在功能实现的基础上,力求程序控件界面美观得体; d) 练习简单应用程序开发设计及程序开发方法。 F) 通过所学知识,尽量在控件中添加更多功能。
3、实验环境(本次上机实验所使用的平台和相关软件) Windows Xp 系统 + Visual Studio 2005 程序软件
2
三、程序设计 ⑴ 根据所需内容,按要求在 WindowsApplication 中添加 ASP.NET Web 控件。 ① 选择工具箱,按需求选择窗体控件添加,如图,
图 2-6
Table 控件,运行结果如图
图 2-7
File Field 控件,实现选择上传文件功能
4Baidu Nhomakorabea
⑵ 为每个控件添加所需的程序 ⑶ 编辑完毕,运行程序,效果如图:
四、程序实现
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls;
8
if(ListBox1.Items[i].ToString()==TextBox3.Text) { ifExist=true; //找到时中断退出 break; }} if(!ifExist) { ListBox1.Items.Add(TextBox3.Text); }} private void Button7_Click(object sender, System.EventArgs e) { for(int i=ListBox1.Items.Count-1;i>=0;i--) { if(ListBox1.Items[i].Selected) { ListBox1.Items.Remove(this.ListBox1.Items[i]); }}} private void Button8_Click(object sender, System.EventArgs e) { { Table1.Rows.Clear(); AddRow("搜狐企业在线","www.sohu.net","包括招商引资、企业报道等信息。"); AddRow("263 在线","www.263.net","包括娱乐、生活、旅游等信息。"); }} private void AddRow(string str1,string url,string str2) { TableRow row=new TableRow(); HyperLink hyperlink=new HyperLink(); hyperlink.Text=str1; hyperlink.NavigateUrl=url; hyperlink.Target="_top"; TableCell cell1=new TableCell(); cell1.Font.Size=FontUnit.XSmall; cell1.Controls.Add(hyperlink);
namespace _123 { /// <summary>
5
/// WebForm1 的摘要说明。 /// </summary> public class WebForm1 : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { ListItem[] stra={ new ListItem("操作系统"),new ListItem("数据结构"),new ListItem("数据库")}; DropDownList1.Items.AddRange(stra); } if(!Page.IsPostBack) { ListItem[] item=new ListItem[10]; for(int i=0;i<item.Length;i++) { item[i]=new ListItem("选项"+i.ToString()); } CheckBoxList1.Items.AddRange(item); } } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 InitializeComponent(); base.OnInit(e); } /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click);
2、需要实现的功能需求 ⑴ 通过 CheckBox 控件,实现事务单项选择功能,并在 TextBox 中显示所选内容。 ⑵ 实现 CheckBoxList 选项列表功能。 ⑶ 实现 CheckedListBox 复选框的多选内容,按钮单击显示 ⑷ 实现 RadioButton 单项选择框的任意选择,通过 Web 网页显示所选的内容。 ⑸ 编辑 RadioButtonList 控件,确定选择之后,在网页中显示所选内容。 ⑹ 进行 ListBox 插入信息在相应文本框中输出,并可进行相应的插入、删除操作。 ⑺ 实现 DropDownList 中下拉选择确定功能。 ⑻ 完成 Table 控件显示的网格线模式,处理表格中信息。 ⑼ 通过相应程序,完成通过网页浏览相关文本,并上传此信息至服务器。 ⑽ 完成 Table 控件在设计模式下向表格添加文本或控件。 ⑾ 掌握 Web 窗体设计模式与 HTML 模式的联合使用。 ⑿ 熟练在代码隐藏类中编写 HTML 及客户端脚本的方法。
② 控件名称
图 2-1 用于多选框选择文字输入,CheckBox 控件
图 2-2 RadioButton 控件所实现的单项选择功能
图 2-3 RadioButtonList 选择框及其效果
3
图 2-4 ListBox 控件,实现向列表框中插入和删除信息功能
图 2-5 DropDownList 控件,实现下拉菜单选择功能
6
this.TextBox1.TextChanged += new System.EventHandler(this.TextBox1_TextChanged); this.Button2.Click += new System.EventHandler(this.Button2_Click); this.Button3.Click += new System.EventHandler(this.Button3_Click); this.Button4.Click += new System.EventHandler(this.Button4_Click); this.Button5.Click += new System.EventHandler(this.Button5_Click); this.Button6.Click += new System.EventHandler(this.Button6_Click); this.Button7.Click += new System.EventHandler(this.Button7_Click); this.Button8.Click += new System.EventHandler(this.Button8_Click); this.Button9.Click += new System.EventHandler(this.Button9_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { Response.Write("<script>window.confirm('ok?');</script>"); } private void TextBox1_TextChanged(object sender, System.EventArgs e) {Response.Write("<script>window.alert('"+this.TextBox1.Text+"')</script>"); } private void Button2_Click(object sender, System.EventArgs e) { string str="选择结果:"; if(CheckBox1.Checked==true) str+=CheckBox1.Text+"、"; if(CheckBox2.Checked==true) str+=CheckBox2.Text+"、"; if(CheckBox3.Checked==true) str+=CheckBox3.Text+"、"; if(str[str.Length-1]=='、') str=str.Substring(0,str.Length-1); TextBox2.Text=str; } private void Button3_Click(object sender, System.EventArgs e) { string str="选择结果:"; for(int i=0;i<CheckBoxList1.Items.Count;i++) { if(CheckBoxList1.Items[i].Selected) {
7
str+=CheckBoxList1.Items[i].Text+"、"; }} if(str[str.Length-1]=='、') str=str.Substring(0,str.Length-1); Response.Write("<script>window.alert('"+str+"');</script>"); Response.Write("<script>window.alert('"+this.TextBox1.Text+"')</script>"); } private void Button4_Click(object sender, System.EventArgs e) { string str="你选择的是:"; if(RadioButton1.Checked) str+=RadioButton1.Text; else if(RadioButton2.Checked) str+=RadioButton2.Text; else if(RadioButton3.Checked) str+=RadioButton3.Text; Response.Write("<script>window.alert('"+str+"')</script>"); } private void Button5_Click(object sender, System.EventArgs e) { string str="你选择的是:"; if(RadioButtonList1.SelectedIndex>-1) { str+=RadioButtonList1.SelectedItem.Text; } Response.Write("<script>window.alert('"+str+"')</script>"); } private void Button6_Click(object sender, System.EventArgs e) { //插入非重复条目 bool ifExist=false; if (TextBox3.Text!="") //for 语句用来查找是否有重复条目,ListBox1.Items.Count 代表列表框中 //条目的个数 for(int i=0;i<ListBox1.Items.Count;i++) {
相关文档
最新文档