Asp.net Array application

Source: Internet
Author: User

Response. Write (array. indexof (ABC, "3", 1); // search for "3" in the ABC array, starting from ABC [1]
Response. Write (array. lastindexof (ABC, "3"); // search for "3" in the ABC array.
------------------------------------------------------------------------------
String [] arrstr = new string [8] {"1", "4", "3", "2", "16", "14", "12 ", "14"}; // arrstr [0] = "1 "... arrstr [7] = "14"
Array. Reverse (arrstr); // reverse the arrstr array. In this case, arrstr [0] = "14"... arrstr [7] = "1"
Array. Sort (arrstr); // sort the array. The order is, or (because it is sorted by string)
------------------------------------------------------------------------------
To redefine the size of an array, redim (VB) must be used. large arrays are very slow, and elements cannot be inserted in the middle. They cannot be cleared (they can only be set to null or 0)
Arraylist is slower than array but does not need to be redefined. You can use myarrlist. Add ("dog") s to conveniently add data.
Arraylist myarrlist = new arraylist (); // you do not need to specify the size of the array. Each element can be of any data type;
Myarrlist. insert (1, "ABC"); // insert an element before array [1]
Myarrlist. removeat (1); // delete an array element [1]
Myarrlist. Remove ("ABC"); // Delete the array elements whose content is "ABC" only once. If you want to delete all elements, perform a loop.
------------------------------------------------------------------------------
Listitem newitem = new listitem (); newitem. Text = "A"; newitem. value = "B ";
Mydropdown. Items. Add (newitem); // use listitem to add an item to the list box.
------------------------------------------------------------------------------
Hashtable ht = new hashtable (); HT ["1"] = "A"; Ht. Add ("2", "A"); // hashtable usage
Sortedlist SL = new sortedlist (); SL ["1"] = "A"; SL. add ("2", "A"); // sortedlist usage, which is automatically sorted by key
Foreach (dictionaryentry ABC in SL) // You can traverse sortedlist.
------------------------------------------------------------------------------
Connstr = @ "provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ ABC. mdb "; // connect to the access database. Add @
Connstr = "Server = 127.0.0.1; database = mydatabase; uid = username; Pwd = password"; // connect to the SQL Server database
Connstr = "provider = sqloledb.1; server = 127.0.0.1; database = mydatabase; initial catalog = mycatalog; uid = username; Pwd = password"; // use oledb to connect to the SQL Server database
------------------------------------------------------------------------------
Connstr = @ "provider = Microsoft. Jet. oledb.4.0; Data Source = c: \ ABC. mdb "; // connect to the access database. Add @
Oledbconnection con = new oledbconnection (connstr); con. open (); con. Close ();
Or
Oledbconnection con = new oledbconnection ();
Con. connectionstring = connstr; con. open (); con. Close ();
------------------------------------------------------------------------------
Oledbconnection con = new oledbconnection (connstr );
Oledbcommand Dc = new oledbcommand ("select * from employees", con );
Oledbdatareader DR = NULL; con. open (); DR = Dc. executereader ();
While (dr. Read () = true) response. Write (Dr ["firstname"] + "<br> ");
Dr. Close (); con. Close (); // The datareader and connection must be closed, and the command does not need
// DR = NULL is not used here, And. NET will automatically complete, but adding DR = NULL will quickly release the memory
------------------------------------------------------------------------------
<Input type = text id = "txthtml" runat = server/>
And
<Asp: textbox id = "txtasp" runat = server/>
Differences:
1.txt ASP uses onclick, while txthtml uses onserverclick
2.txt ASP uses text to set and obtain values, while txthtml uses txthtml. Value to set and obtain values.
3. <span id = "sum" runat = server/> use the innertext attribute to write data.
------------------------------------------------------------------------------

Controls:
<Asp: ListBox id = "mylist" runat = server rows = 6 selectionmode = "multiple">
<Asp: listitem text = "A" selected = "true" runat = server/>
</ASP: ListBox>
Arraylist A = new arraylist (); For (INT I = 0; I <mylist. items. count; I ++) {If (mylist. items [I]. selected). add (I );}
<Asp: dropdownlist id = "myddlist" runat = Server> the rows and selectionmode attributes are not available.
<Asp: checkboxlist id = "cblist" runat = server cellpadding = 0 cellspacing = 0
Repeatcolumns = 3 repeatdirection = "horizontal" or "vertical">
<Asp: listitem text = "A" selected = "true" runat = server/>
</ASP: checkboxlist>
<Asp: radiobuttonlist id = "rblist" runat = server cellpadding = 0 cellspacing = 0
Repeatcolumns = 3 repeatdirection = "horizontal" or "vertical">
List. selecteditem. Text; List. selectedindex; List. items [I]. selected;
List. Items. insert (0, new listitem ("all", "-1 "));
After adding the detailed information, execute the following two statements:
Select_info.items.add ("choose one Department ");
Select_info.selectedindex = select_kc.Items.Count-1;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.