Learning every language is essential to learning controls. Controls in the development environment of each language are similar. The Asp.net control is very simple. You can set the properties of the control to directly use the control. In CS, if the control needs to verify whether it is empty, you need to write code. This is the advantage of Asp.net.
Every time you click a button, linkbutton, imagebutton, or other controls on an ASP. NET web page, the form is sent to the server. If the autopostback attribute of the control is set to true, a request is sent to the server every time the control status changes. This type of frequent dealings with the server increases the pressure on the server, so now Ajax is used.
Asp.net control summary:
There are a total of four types of Asp.net controls, and each type is used in the same way, as long as you know their differences, you can easily master it.
For example:
Use of the Repeater control: the Repeater control displays a list of duplicate projects, which are restricted in the control. The Repeater control has five templates, which can be applied below.
Web form code:
<Asp: Panel id = "Panel1" runat = "server" Height = "297px" width = "496px"> <asp: repeater id = "repeater1" runat = "server"> <itemtemplate> <% # databinder. eval (container. dataitem, "PID") %> <% # databinder. eval (container. dataitem, "personname") %> </itemtemplate> <alternatingitemtemplate> <font color = "red"> <% # databinder. eval (container. dataitem, "PID") %> <br/> <% # databinder. eval (container. dataitem, "personname ") %> </font> </alternatingitemtemplate>
Background code:
Public partial class repeatercontrol: system. Web. UI. Page {protected void page_load (Object sender, eventargs e) {If (! This. ispostback) {This. label3.text = "1"; this. databindtorepeater () ;}/// <summary> /// construct a method to open the database and query data in the database, and display it by PAGE /// </Summary> private void databindtorepeater () {// define the current page int curpage = convert. toint32 (this. label3.text); // connect to open the database and query sqlconnection con = dB. createcon (); sqldataadapter SDA = new sqldataadapter (); SDA. selectcommand = new sqlcommand ("select * From person", con); dataset DS = new dataset (); SDA. fill (DS, "Ado"); system. web. UI. webcontrols. pageddatasource PS = new pageddatasource (); PS. datasource = Ds. tables ["Ado"]. defaultview; PS. allowpaging = true; // three lines of PS are displayed on each page. pagesize = 3; PS. currentpageindex = curpage-1; this. button1.enabled = true; this. button2.enabled = true; // if it is the first page, the previous page button cannot use if (curpage = 1) {This. button1.enabled = false;} // If the button is next to the last page, if (curpage = ps. pagecount) {This. button2.enabled = false;} // bind the data source to this. repeater1.datasource = Ps; this. repeater1.databind ();} /// <summary> // Previous Page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void button#click (Object sender, eventargs e) {// forcibly convert label3 content to string type this. label3.text = convert. tostring (convert. toint32 (this. label3.text)-1); this. databindtorepeater ();} /// <summary> /// next page // </Summary> /// <Param name = "sender"> </param> /// <Param name =" E "> </param> protected void button2_click (Object sender, eventargs e) {// forcibly convert label3 content to string type this. label3.text = convert. tostring (convert. toint32 (this. label3.text) + 1); this. databindtorepeater ();}}
Display result:
This is done.
Summary:
The five templates of the Repeater control are
<Itemtemplate> </itemtemplate>: displays the HTML elements and controls for each data item in the data source.
<Alternatingitemtemplate> </alternatingitemtemplate>: displays the HTML elements and controls for each data item in the data source.
<Headertemplate> <Footertemplate> </footertemplate>: contains the text and controls displayed at the end of the list.
<Separatortemplate> </separatortemplate>: contains the elements presented between each item. A typical example is a straight line.