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;
namespace net2
{
/// <summary>
/// webform5 的摘要说明。
/// </summary>
public class webform5 : system.web.ui.page
{ //protected 保护类型。 要想在aspx哪个页面访问的时候就必须用到保护类型以上的 private估计是不行的
protected system.web.ui.webcontrols.dropdownlist dropdownlist1;
protected system.web.ui.webcontrols.listbox listbox1;
protected system.web.ui.webcontrols.radiobuttonlist radiobuttonlist1;
protected system.web.ui.webcontrols.label label1;
protected system.web.ui.webcontrols.button button1;
protected system.web.ui.webcontrols.label label2;
protected system.web.ui.webcontrols.label label3;
protected system.web.ui.webcontrols.label label4;
protected system.web.ui.webcontrols.checkboxlist checkboxlist1;
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
//一些web控件,如果没有选择它的值。然后又要取出它的值。那么它就会出错了
if (! ispostback)
{
//第一个是数组了
string[] str1 = new string[3]{"*","**","***"};//还有一个定义数组的方法 string[] str1= new string[3];str1[0]="";在初值化
//搞不懂是不是数组的意思。 中文也是可以在这边使用的
arraylist 选项 = new arraylist();
选项.add("第一个");
选项.add("第二个");
选项.add("第三个");
选项.add("第四个");
选项.add("第五个");
//hashtable 是不可以用排序的!
hashtable ht = new hashtable();
ht.add("1","a");
ht.add("2","b");
ht.add("3","c");
ht.add("4","d");
ht.add("5","e");
//sortedlist 可以自动进行排序
sortedlist sl = new sortedlist();
sl.add("1","a");
sl.add("2","b");
sl.add("3","c");
sl.add("4","d");
sl.add("5","e");
//也可以使用xml进行绑定 dataset
dataset ds = new dataset();
ds.readxml(mappath("countries.xml"));
/*
<?xml version="1.0" encoding="iso-8859-1"?>
<!– edited with xml spy v4.2 –>
<countries>
<country>
<text>norway</text>
<value>n</value>
</country>
<country>
<text>sweden</text>
<value>s</value>
</country>
<country>
<text>france</text>
<value>f</value>
</country>
<country>
<text>italy</text>
<value>i</value>
</country>
</countries>
*/
dropdownlist1.datasource=str1;
dropdownlist1.databind();
listbox1.datasource=选项;
listbox1.databind();
radiobuttonlist1.datasource=sl;//用来试验hashtable 和sortedlist
radiobuttonlist1.datavaluefield="value";
radiobuttonlist1.datatextfield="key";
radiobuttonlist1.databind();
checkboxlist1.datasource=ds;
checkboxlist1.datavaluefield="value"; //这边的格式是xml里的
checkboxlist1.datatextfield="text";
checkboxlist1.databind();
}
}
#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);
this.load += new system.eventhandler(this.page_load);
}
#endregion
private void button1_click(object sender, system.eventargs e)
{
label1.text="dropdownlist1:"+dropdownlist1.selecteditem.text;
label2.text="listbox1:"+listbox1.selecteditem.text;
//分析label3的不同之处
label3.text="radionbuttonlist:"+radiobuttonlist1.selecteditem.text+radiobuttonlist1.selectedvalue;
label4.text="checkboxlist1:"+checkboxlist1.selecteditem.value;
}
}
}
