Asp.net| Array
String[] abc=new string[8]{"1", "2", "3", "4", "1", "2", "3", "4"};
Response.Write (Array.indexof (ABC, "3", 1))//Look for "3" in the ABC array, starting from abc[1]
Response.Write (Array.lastindexof (ABC, "3"))//Look for "3" in the ABC array, starting from the last
------------------------------------------------------------------------------
String[] arrstr=new string[8]{"1", "4", "3", "2", "The" "," "," "," ","};//arrstr[0]= "1" ... arrstr[7]= "14"
Array.reverse (ARRSTR); Reverse Arrstr Array, at this time arrstr[0]= ... arrstr[7]= "1"
Array.Sort (ARRSTR); Sort the array, at which point the order is 1,12,14,14,16,2,3,4 (because it is sorted by string)
------------------------------------------------------------------------------
Array arrays to redefine size, must be in ReDim (VB), particularly slow for large arrays, and cannot be inserted in the middle; you cannot clear them (only set to null or 0)
ArrayList is slower to use than array, but does not need to redefine size, using Myarrlist.add ("Dog") s makes it easy to add data
ArrayList myarrlist = new ArrayList ();//Do not indicate the size of the array, and each element can be any data type;
Myarrlist.insert (1, "abc"); Insert element to array [1] Before
Myarrlist.removeat (1); Delete array elements [1]
Myarrlist.remove ("abc"); Delete an array element with the content "ABC", delete only once, and if you want to erase it all, you need to do a loop
------------------------------------------------------------------------------
ListItem newitem=new ListItem (); newitem.text= "a"; newitem.value= "B";
MYDROPDOWN.ITEMS.ADD (newitem);//Use ListItem to add items to the list box
------------------------------------------------------------------------------
Hashtable HT =new Hashtable (); ht["1"]= "a"; Ht. ADD ("2", "a");//hashtable usage
SortedList sl=new SortedList (); sl["1"]= "a"; ADD ("2", "a"),//sortedlist usage, automatically sorted according to key
foreach (DictionaryEntry ABC in SL)//Traversal SortedList approach
------------------------------------------------------------------------------
connstr=@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\abc.mdb";//Connect to an Access database, note that the @ is added
Connstr= "Server=127.0.0.1;database=mydatabase;uid=username;pwd=password";//Connect SQL Server Database
Connstr= "Provider=SQLOLEDB.1; Server=127.0.0.1;database=mydatabase;initial Catalog=mycatalog;uid=username;pwd=password ";//OLE DB connection SQL Server database
------------------------------------------------------------------------------
connstr=@ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\abc.mdb";//Connect to an Access database, note that the @ is added
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 ();d R=DC. ExecuteReader ();
while (Dr. Read () ==true) Response.Write (dr["FirstName"]+ "<BR>");
Dr. Close (); con. Close ();//datareader and connection to be closed, command not
There is no dr=null here. NET will be completed automatically, but plus dr=null will release the memory faster
------------------------------------------------------------------------------
<input type=text id= "txthtml" Runat=server/>
And
<asp:textbox id= "txtasp" Runat=server/>
The difference between:
1.TXTASP uses onclick, while txthtml uses OnServerClick
2.TXTASP uses text to set and get values, and txthtml uses Txthtml.value to set and get values
The 3.<span id= "sum" Runat=server/> is written using the innertext attribute.
------------------------------------------------------------------------------
Control:
<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) A.add (i);}
<asp:dropdownlist id= "Myddlist" runat=server> no rows and SelectionMode properties
<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 you add the details, the last two sentences are executed.
Select_info. Items.Add ("Choose one department");
Select_info. SELECTEDINDEX=SELECT_KC. items.count-1;