ASP.Net front desk to call back variable method

Original link: http://www.cnblogs.com/luofeng99/archive/2011/12/01/2297805.html

 

09:55:48 2009-06-10 | Category: Programming meta | Tags: | Font sizeDa Zhong small subscription 

Gridview row bind call back method

Bound to the label or the textbox Text = '<% # LabelText (Convert.ToString (Eval ( "bound field")))%> ">

LabelText return parameters in the background with a method for the

protected string LabelText(string label)

{

return label;

}

 

Net call the front desk background variables

 

Several 1.Asp.Net like reference numerals: <% = ...%> <% ...% #> <%> <% @%> Definitions and Usage

A: <% # ...%>: when binding is performed in the control DataBind () method performs, for data binding as: <% # Container.DataItem ( "tit")%>

<% =%>: It is called when the program is executed, the variable value can be displayed as the background: * .aspx in: <% = aaa%> * .cs in: protected string aaa = "name";

<%>: Inline code blocks which may be embedded in the code behind or inside * .aspx page file * .ascx file as: <% for (int i = 0; i <100 i = "" reaponse = "" write = "" i = "" tostring = ""> <% @%> is introduced into the namespace * .aspx page reception codes, such as: <% @ import namespace = "System.Data"%>

2. What types of data control receives A:? Reception Bind controls, generally DropDownList, DataList, DataGrid, ListBox control the nature of these collections, which were tied mainly ArrayList (array), Hashtable (Ha dilute table), DataView ( data view), DataReader four, then we can pigeon-holing, DataTable error does not appear to be tied up :)

3.DataBind, the data obtained, the system will default to String, how converted to other types? DataBinder.Eval (Container.DataItem, "type conversion" and "format") last "format" is optional , generally do not have to control him, Container.DataItem bundled data entry, "conversion type" refers to the Integer, String, Boolean this type of thing.

4. The main namespaces: used when <%% @ Import Namespace = "System.Data"> Data Processing <% @ Import Namespace = "System.Data.ADO"%> using the ADO.net; when used <% @ Import Namespace = "System.Data.SQL"%> SQL Server database-specific <% @ Import Namespace = "System.Data.XML"%> do not look at processing XML use <% @ Import Namespace = "System.IO"%> used 5.Connections (SQLConection when to use <% @ Import Namespace = "System.Web.Util"%> processing files we will use <% @ Import Namespace = "System.Text"%> text encoding when mail or ADOConnection) of common attributes and methods: | ConnectionString statements made or set up a database link | ConnectionTimeout get or set the maximum time a database link, also on timeout | dataBase acquire or set up on the database server to open the database name | DataSource get or set the DSN, we will not be unfamiliar to you :) | password get or set the password | UserID get or set the login name | state acquired the status of current links | open () to open links | Close () to close coupling | clone (a clone) Link. (Oh, I can sheep may Connection) Example: HasChanges) {// save the code because there is no} else {// change, so do not saved, saving time updating the database} f MyComm.Update (MyDataSet);. // update the database all the tables MyComm.Update (MyDataSet, " UserList "); // update a table 9.DataGrid implement paging function AllowPaging =" True "// means allow paging, this is the most important. With it, we can paging. PageSize = "5" // specifying the number of records per page, and if you do not write, it will default to 10. PagerStyle-HorizontalAlign = "Right" // specified positioning facet displayed default Left PagerStyle-NextPageText = "Next" // the <> to the previous and next string PagerStyle-PrevPageText = " Previous "PagerStyle-Mode =" NumericPages "// the <> 123 to a digital display 10 displays the total number of pages, and reports the current of the first few pages this page is: <% = DataGrid1.CurrentPageIndex + 1%> total number of pages is: <% = DataGrid1.PageCount%> 11. personalization tab programmer base camp "intimate contact ASP.Net (14)" complete CODE 12. to reset the page valid state IValidator val; foreach (val in Validators) {Val.IsValid = true;} 13. re-execute the entire authentication sequence IValidator val; foreach (val in Validators) {Val.Validate ();} 14. disable client authentication < % @ Page Language = "c #" clienttarget = downlevel%> 15.Repeater, DataList and DataGrid controls the use of "these controls can simplify several common Web application scenarios, including reporting, shopping cart, product list, search results and navigation menu . Repeater is the only allowed HTML fragment in its template controls 16.Server.Execute ( "another.aspx") and Server.Transfer ( "another.aspx") the difference between:. Execute is transferred from the current page to a specified page, and execution returns to the current page transfer is to perform a full transfer to a specific page 17.XML file architecture can be there yourself, you can also exist in the * .xsl file, but must be specified at the root xml document by xmlns attribute this information, as follows: to read the file 18.XML FileStream myfs = new Filestream (Server.MapPath ( "xmldtagrid.xml"), FileMode.Open, FileAccess.Read); StreamReader myreader = new StreamReader (myfs); DataSet 19. the value of the regular expression control RegularExpressionValidator symbol meaning ^ $ designated inspection start at a specified end of the check [] check the input; myds.ReadXml (myreader); () myds = new DataSet If one of the characters in square brackets matches \ W allowed to enter any value \ designation input d {} "\ d" is a number, {} indicates the number of occurrences of the specified data type has one or more elements indicate + It will be added to the sample being examined the expression: E-mail format (having a @ number, and at .com / .net / .org / end .edu) validationexpression = " . ^ [\ W -] + @ [\ w -] + \ (com | net | org | edu) $ "20.DataGrid control data manipulation important statement: Attribute: DataKeyField =" userid "// set the table for the userid primary key, the value field is not updated to the database, the best set table's primary key is the primary key DataGrid SqlCommand.Parameters [ "@ userid"] value = dg.DataKeys [(int) e.Item.ItemIndex];. / / retrieval to be updated primary key row (the row currently selected is assigned to the primary key value of a command parameter) number SqlCommand.Parameters [ "@ fname"]. Value = ((TextBox) e.Item.Cells [2 .] .Controls [0]) Text; // custom given row 21. the value of the modified parameters: a user control (ASP create the same page) (I) to create the page, drag controls, set properties /. method. <% @Control Language = "C #" Debug = "True"%> @ control instructions defined in the page will contain control codes (II) * .ascx saved as a file, such as a.ascx. (III). use: head <% @ Register Tagprefix = "MyFirstControl" TagName = "MyLbl" Src = "a.axcs"%> // Tagprefix prefix control, like ASP: TextBox is used to specify custom ASP // TagName the name of the source file // Src specified control body:. b created from the use of C # Defined control (I) to create pure code file, it inherits Control, and saved as * .cs, as a.cs. (II) compiled code assembly:.. Csc / t: library /r:System.dll , System.Web. Dll a.cs // library tells the C # compiler generates assembly // /r:System.dll System.Web.Dll tell C # compiler reference assemblies (III) specified would generate dll file in the bin directory ( . IV) use: <% @Register TagPrefix = "Mine" Namespace = "MyOwnControls" Assembly = "a"%> 22. composite controls Note: public class MyCompositin: control, INamingContainer // INamingContainer: If you have more on the page one example of this control, this port can knot {} // for each instance has a unique flag this.EnsureChildControls (); // shows a composite control child controls are rendered on the page, check whether this server control method comprising a sub- controls CreateChildControls 23.Button / LinkButton / ImageButton / HyperLink when to use? 1.Button and ImageButton used to pass data back to the server. 2.Hyperlink used to navigate between pages 3.LinkButton for saving data to a server or access 24. the data on the server trace debug trace: 1. page level tracking: beginning of the page including the instruction page <% @ page trace = "True" TraceMode = "SortByCategory / SortByTime"%> custom message in: Trace.Wri te ( "String here to display"); Trace.Warn ( "string to be displayed here"); // and Trace.Write the same, but the font is red Check that the tracking sentence: if (Trace .IsEnabled) {Trace.Warn ( "enabled tracking" )} 2. Application level tracing: in Section 25. Web.config file cache is provided: 1. Output buffer: I. Page Setup: <%% @ OutputCache Duration = "120" VaryByParam = "none"> plus required at the beginning of the page buffer Notes: within two minutes after the page request, the program outputs the contents II invariant manner: (1) the main class using the class System.Web.HttpCachePolicy Response.Cache.SetExpires (DateTime.Now.AddSeconds (120)); // must be specified expiration time in this process, as in the present language sentence // two minutes (2) Response.Cache.SetExpires (DateTime.Now.AddSeconds (120). ); Response.Cache.SetSlidingExpiration (true); // "adjustable expired", mainly for those who start Sheremetyevo, but then access // balancing case features: the first sentence set the cache expiration time, the first two line open sliding expiration (adjustable expired) 2. data cache: (1) .DataView mySource; (2) assigned to mySource; (3) .Cache [ "myCache"] = mySource; (4) .mySource.. = (DataView) Cache [ "myCache"] 26. deployment: directly copied to the production server to copy the statement: XCOPY // XOPY only accept physical path, do not accept the virtual path 2 6. 1. Copy Button custom paging code is the code below: protected void ItemCreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {System.Web.UI.WebControls.

Reproduced in: https: //www.cnblogs.com/luofeng99/archive/2011/12/01/2297805.html

Guess you like

Origin blog.csdn.net/weixin_30193897/article/details/94880609