asp.net| data |asp.net 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>
Summary description of the WEBFORM5.
</summary>
public class WebForm5:System.Web.UI.Page
{//protected protection type. If you want to access the ASPX page, you must use the protection type above the private estimate is not possible.
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)
{
Place user code here to initialize page
Some Web controls, if their values are not selected. Then you have to take out its value again. Then it's going to go wrong.
if (! IsPostBack)
{
The first one is an array.
string[] str1 = new string[3]{"*", "* *", "* *"};//There is also a method to define the array string[] str1= new string[3];str1[0]= ""; in the initialization
Do not understand is not the meaning of the array. Chinese can also be used here.
ArrayList option = new ArrayList ();
Options. ADD ("first");
Options. ADD ("second");
Options. Add ("third");
Options. Add ("Fourth");
Options. Add ("fifth");
Hashtable is not to be sorted by!
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 can be sorted automatically
SortedList SL = new SortedList ();
Sl. ADD ("1", "A");
Sl. ADD ("2", "B");
Sl. ADD ("3", "C");
Sl. ADD ("4", "D");
Sl. ADD ("5", "E");
You can also use XML to bind a 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= option;
Listbox1.databind ();
radiobuttonlist1.datasource=sl;//used to test Hashtable and SortedList.
Radiobuttonlist1.datavaluefield= "Value";
Radiobuttonlist1.datatextfield= "Key";
Radiobuttonlist1.databind ();
Checkboxlist1.datasource=ds;
Checkboxlist1.datavaluefield= "Value"; The format here is in XML.
checkboxlist1.datatextfield= "Text";
Checkboxlist1.databind ();
}
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</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;
Analysis of the differences between LABEL3
label3.text= "radionbuttonlist:" +radiobuttonlist1.selecteditem.text+radiobuttonlist1.selectedvalue;
Lab