More than one months of asp.net+c# learning experience

Source: Internet
Author: User
0. Some programming phrases: string Fdwmc=textbox1.text.trim ();
  ArrayList value=new ArrayList (); Value.
  ADD ("AAA"); Value.

  ADD ("BBB");
  Hashtable h=new Hashtable ();
  H.add ("A1", "A2");
  
  H.add ("B1", "B2");
  StringBuilder s3 = new StringBuilder (); S3.
  Append ("Hello"); S3.
  Append ("World"); S3.

Append ("!!!"); 00.HTML phrase: <p> is to represent paragraph callout <br> break mark, this annotation does not need to write a pair of </br> <font> annotation: This annotation is used to set text size, color, font
   ;b> Bold, <i> italic and <u> bottom line callout  Reply: 
8.DataGrid Data Editing (i) _ Direct edit private void Datagrid1_editcommand (object source,
	System.Web.UI.WebControls.DataGridCommandEventArgs e) {datagrid1.edititemindex= (int) E.item.itemindex;
  Bindgrid (); private void Datagrid1_cancelcommand (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {DATAGR Id1.
	Edititemindex=-1;
  Bindgrid (); } private void Datagrid1_updatecommand (object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {Da	
			
     Tagrid1.edititemindex=-1;
     SqlConnection sqlconn;
     DataSet objdataset=new DataSet ();
     String connstr=configurationsettings.appsettings["strconn"];
     String sqlstr= "select * from Khxx";
     Sqlconn=new SqlConnection (CONNSTR);
     SqlDataAdapter Objadapter=new SqlDataAdapter (Sqlstr,sqlconn);

     Objadapter.fill (Objdataset, "khxx");
     TextBox Currenttext; Currenttext = (TextBox) e.item.cells[1]. controls[0];//Gets the text box objdataset.tables["Khxx"]. rows[(int) e.item.itemindex]["KHJC"]=currentteXt.

     Text;
     SqlCommandBuilder cb=new SqlCommandBuilder (objadapter);
     Sqlconn.open ();
     Objadapter.update (Objdataset, "khxx");

     Sqlconn.close ();
     datagrid1.datasource=objdataset.tables["Khxx"];

   Datagrid1.databind ();
   In Pageload () must have if (Page.IsPostBack) {...};

Datagrid1.datakeyfield= "KHBH"; 8. Sort: private void Datagrid1_sortcommand (object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) {D
	Atagrid1.edititemindex=-1;
	SqlConnection sqlconn;
	DataSet objdataset=new DataSet ();
	String connstr=configurationsettings.appsettings["strconn"];
	String sqlstr= "select * from Khxx";
	Sqlconn=new SqlConnection (CONNSTR);
	SqlDataAdapter Objadapter=new SqlDataAdapter (Sqlstr,sqlconn);

	Objadapter.fill (Objdataset, "khxx");
	DataTable objdatatable=objdataset.tables["Khxx"];
	DataView objdataview=new DataView (objdatatable);

	Objdataview.sort=e.sortexpression;
	Datagrid1.datasource=objdataview;
  Datagrid1.databind ();
} datagrid1.allowsorting=true;  <asp:boundcolumn datafield= "KHBH" readonly= "True" headertext= "customer number" sortexpression= "KHBH" > <itemstyle Wrap= "False" ></ItemStyle></asp:BoundColumn> 9. Delete a record: private void Datagrid1_deletecommand (object source,
	System.Web.UI.WebControls.DataGridCommandEventArgs e) {SqlConnection sqlconn;
	DataSet objdataset=new DataSet ();
	String connstr=configurationsettings.appsettings["strconn"];

	Sqlconn=new SqlConnection (CONNSTR); String Bh=datagrid1.datakeys[e.item.itemindex].
	ToString ();
        String sqlstr= "Delete from khxx where khbh= '" +bh+ "";
        int ProductID = (int) mydatagrid.datakeys[(int) e.item.itemindex]; String sqlstatement= "Delete products WHERE productid=" +productid (When the field is an integer) SqlCommand mycommand = new SqlCommand (SQ

	Lstr,sqlconn);
	MyCommand.Connection.Open ();
	Mycommand.executenonquery ();

	MyCommand.Connection.Close ();
  Bindgrid (); 10. Prompt for deletion when deleting: <HEAD> ... <script language= "javascript" > function delete_confirm(e) {if (event.srcelement.outertext== "delete") event.returnvalue=confirm ("Confirm deletion No.")
               ");
	} document.onclick=delete_confirm;
  </script> </HEAD> 11. Add check box to the DataGrid. <Columns> <asp:templatecolumn headertext= "" itemstyle-horizontalalign= "Center" > <ItemTemplate> &L T;asp:checkbox runat= "Server" id= "del"/> </ItemTemplate> </asp:TemplateColumn> ... </co
	Lumns> 12. Select Delete multiple records: private void Button1_Click (object sender, System.EventArgs e) {SqlConnection sqlconn;
	String connstr=configurationsettings.appsettings["strconn"];

	Sqlconn=new SqlConnection (CONNSTR);
	String Delstring,sidstring= "";
		for (int i=0;i<datagrid1.items.count;i++) {CheckBox h; H= (CheckBox) datagrid1.items[i]. Cells[0].
		CONTROLS[1]; if (h.checked = = true) {//Get the selected primary key sidstring + = "or (KHBH = '" + datagrid1.items[i]. CELLS[1].
		Text + "')"; } if (sidstring.length>0) {sidstring=sidstring.remove (0),4);
		delstring = "Delete from khxx where" + sidstring;
		SqlCommand Delrec = new SqlCommand (delstring,sqlconn);
		DelRec.Connection.Open ();
		Delrec.executenonquery ();
		DelRec.Connection.Close ();
	Bindgrid (); } 13. Different Web page pass parameters (previous backward one): (WebForm1.aspx) private void button2_click (object sender, System.EventArgs e) {Res Ponse.
  Redirect ("webform2.aspx@id=" +textbox1.text+ "&name=" +textbox2.text);
	} (webform2.aspx) private void Page_Load (object sender, System.EventArgs e) {string S;
	s=request.querystring["ID"];
	Label1.text=s;
	s=request.querystring["NAME"];		
  Label2.text=s;

 }
Reply:
14. Add one record (i): SqlConnection sqlconn;
	DataSet objdataset=new DataSet ();
	String connstr=configurationsettings.appsettings["strconn"];
	String sqlstr= "select * from Khxx";
	Sqlconn=new SqlConnection (CONNSTR);
	SqlDataAdapter Objadapter=new SqlDataAdapter (Sqlstr,sqlconn);

	Objadapter.fill (Objdataset, "khxx"); DataRow Row=objdataset.tables[0].
	NewRow ();
	row["KHBH"]=textbox3.text;
	row["KHJC"]=textbox4.text;
	row["DH"]=textbox5.text;
	row["Cjri"]=textbox6.text;

	row["BYCGL"]=textbox7.text; Objdataset.tables[0].
	Rows.Add (row);
	SqlCommandBuilder cb=new SqlCommandBuilder (objadapter); Objadapter.update (Objdataset,objdataset.tables[0].
	ToString ());
Bindgrid ();

15. Code Color: linkbutton1.forecolor=colortranslator.fromhtml ("#FF8000"); 16. About loading execution: protected void Page_Load (Object sender, EventArgs e) {//web page at each load, some operations performed if (!).  

IsPostBack {///////* actions performed at first load of the Web page/else {///Loopback action}//web page action to be performed at each load 17. Full screen view when opening Web page: (PlusDefault.aspx, add: <script language= "JavaScript" > window.open (' loadfile.aspx.html ', ' _blank ', ' menubar=no, 
  Location=no,toolbar=no, scrollbars=no,status=no,top=0,left=0,width= ' + Screen.width + ', height= ' + screen.height);
  Window.opener = null;
  Window.close (); </script> 18. Open a new browser window: Response.Write ("<script language= ' JavaScript" > window.open (' yoururl ') </

Script> "); 19. When the page starts up a small form: in the Page_lod event to add: Response.Write ("<script>window.open" ("newyear.htm", ' _blank ', ' toolbar=no, Location=no,directories=no,status=no, Menubar=no,scrollbars=no,revisable=no,left=100,top=0,width=600,height=50 '
   ) </"+" script> "); Pop-up filename: newyear.htm 20.Session Usage://pass parameter session["Markid" = WebForm1.
  Text1.value; application["Markid"] = WebForm1.
  Text1.value; WebForm2.Text1.Value = session["Markid"].
  ToString (); WebForm2.Text1.Value = application["Markid"].

  ToString (); Clear Session.remove ("Markid"); (Session can be defined anywhere in the WebForm1.) ) 21.html Control: Button cursorMove up the different effect of moving up: <input id= "Button3" style= "z-index:111; left:248px; 
  Position:absolute;
  Top:456px "onmouseover=" this.style.color= ' red '; onmouseout= "this.style.color= ' black ';" type= "button" value= "text" name= "Button3" runat= "Server" > 22.cookie usage: Ht
  Tpcookie cookie = new HttpCookie ("ASPCN"); Cookie.
  Values.add ("webmaster", "flying Knife"); Cookie.
  Values.add ("writer", "Beige"); Cookie.
  Values.add ("LinkColor", "Blue");
  Response.appendcookie (cookie);
  Taking out information is just as simple httpcookie cookies = request.cookies["ASPCN"]; value1 = cookies.
  values["Webmaster"]; value2 = cookies.

values["Writer"]; 23.ASP. NET Chinese display of several kinds of solutions: (1) configuration> <globalization requestencoding= "Utf-8" responseencoding

= "Utf-8"/> </configuration> or "gb2312" or "Big5" (2) Add <%@ CODEPAGE = "936"%> to the beginning of each page; 24. Online User statistics: private void Page_Load (object sender, System.EventArgs e) {visitors.text = application["User_sessi" ONS "].
  ToString (); } Global.asax file: protected void Application_Start (Object sender, EventArgs e) {application["user_sessions"] = 0;
   } protected void Session_Start (Object sender, EventArgs e) {application.lock ();
   application["user_sessions"] = (int) application["user_sessions"] + 1;
  Application.UnLock ();
    } protected void Session_End (Object sender, EventArgs e) {application.lock ();
    application["user_sessions"] = (int) application["User_sessions"]-1;
  Application.UnLock ();
  A traversal modification method for 25.DataSet: SqlDataAdapter Mycmd=new SqlDataAdapter (Strsql,myconn);
  DataSet ds=new DataSet ();
  Mycmd.fill (ds, "operator"); for (int i=0;i<ds. Tables[0]. rows.count;i++) {if (ds. Tables[0]. rows[i]["Oper_state"]. ToString () = = "1") ds. Tables[0].
   rows[i]["Oper_state"]= "effective"; else if (ds. Tables[0]. rows[i]["Oper_state"]. ToString () = = "0") ds. Tables[0].
  rows[i]["Oper_state"]= "Frozen"; 26. Automatic refresh:   

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.