Some of the data bindings in ASP.NET

xiaoxiao2021-03-06  41

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 {///

/// WebForm5 summary description. /// public class Webform5: system.Web.ui.page {// protected protection type. To access the pages when aspx which would be used to protect more than the type of private estimate is not enough 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) {// Put user here The code is in an initialization page // some web controls, if there is no value to choose. Then take out its value. Then it will have an error (! Ispostback) {// The first is an array of String [] str1 = new string [3] {"*", "**", "***"}; // There is a method of defining an array String [] str1 = new string [3]; str1 [0] = ""; in primary value // does not understand is the meaning of array.

Chinese is also an arraylist option that can be used here = new arraylist (); option .Add ("first"); option .add ("second"); option .add ("third"); option .Add ("fourth"); option .add ("fifth"); // hashtable is not sorted! 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 automatically sort 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 DataSet Dataset DS = New Dataset (); DS.Readxml (MAPPATH (" COUNTRIES.XML ")); / * norway n < Text> sweden s France f italy < / text> I * / 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.database ();

CheckBoxList1.datasource = DS; checkboxlist1.datavaluefield = "value"; // This format is the checkboxlist1.datatextField = "text" in XML; checkboxlist1.database ();}} #Region web form designer generated code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private () {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 different label3 at Label3.Text = "RadionButtonList:" RadioButtonList1.SelectedItem.Text RadioButtonList1.SelectedValue; Label4.Text = "CheckBoxList1:" CheckBoxList1.SelectedItem.Value;}}}

转载请注明原文地址:https://www.9cbs.com/read-73880.html

New Post(0)