ASP. NET study note _ 09 Repeater

Source: Internet
Author: User

1,

Data Binding
Combox --> bingdsource --> objectdatasource

// Connect to the database
** BackgroundCode:

T_usertableadapter adpter = t_usertableadpter ();
Adpater. Call the User-Defined method of the t_user table

// Set the initial data:
Appenddatebource = "true ";

 

2. Repeater dynamically displays all data in the data table: (equivalent to a for statement I think)

# Indicates binding data
(1) template: <itemtemplate> primary key: <% # eval ("ID") %> </itemtemplate>
(2) Other templates (display across rows): <alternatingtemplate> </alternatingtemplate>
(3) the header and tail templates

(4) You can call the server-side function in <% AAA (eval ("A") %>.
Protected string AAA (Object URL ){
Return resolveclienturl ("/.../" + URL );
}

(5) common types of statements:

** 1: E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem
The trigger type is the basic row or content row in dadalist: used to determine whether the item is an item in the control content or a plug-in item.

** 2: E. Item. itemtype = listitemtype. Header
It refers to the content of the title row in the "dadalist" trigger type: used to determine whether the item is the header of the control.

** 3 search materials:

For the listitemtype enumeration [C #], see
System. Web. UI. webcontrols namespace | datagriditem. itemtype | datalistitem. itemtype | repeateritem. itemtype
Namespace: system. Web. UI. webcontrols

Listitemtype enumeration indicates different items that can be included in the list control, such as DataGrid, datalist, and repeater. A typical list control consists of cells that contain elements represented by this enumeration.

Member
Member Name Description
Alternatingitem alternate (an even index starting from scratch) items in cells. It is bound to Data.
The items in editing mode in the edititem list control. It is bound to Data.
Footer of the footer list control. It is not bound to Data.
The header of the header list control. It is not bound to Data.
Items in the item list control. It is bound to Data.
The pager page navigation shows the controls that are located on different pages associated with the DataGrid Control. It is not bound to Data.
Select items in the selecteditem list control. It is bound to Data.
Delimiter between items in the separator list control. It is not bound to Data.

3. itemdatabound event of repeater event

(1. onitemdatabound event (obtains information about the same row in the binding)

Datarowview myrow = (datarowview) E. Item. dataitem;
Myrow ["here is the name of the relevant field"]

(2. Background code: Get columns in the database table

// Retrieve the bound row Information
Datarowview view = (datarowview) E. Item. dataitem;
// Strong connection
VaR ROW = (project name/folder name/Dal/datasetpersons/t_personsrow) view. row;

(3. Background code: the ID in the master cannot be directly obtained.

// Obtain the ID
Textbox txtid = (textbox) E. Item. findcontrol ("ID ");
// Perform operations by ID
Txtid. backcolor = color. Red;

(4. In aspx: href = '<% # eval ("url") %>'

In this way, clicking in the browser will not go to the specified page and should be changed
Href = 'HTTP: // <% # eval ("url") %>'

(5. supported formats in aspx
<% # Eval ("date", "yyyy-mm-dd") %>

4. itemcommand event of repeater event

** E. commandname
** E. commandargument Parameters

** The background code obtains the parameters passed by the foreground, such as ID: Long id = convert. toint64 (E. commandargument );

** Background code: repeater. databing // force refresh data

 

(1. onclientclick = "Return confirm (" Do you really want to operate? ");"

(2) Check the type of the ID in Aspx. You can first create an ID and then view the type in Aspx. CS.
// Usage:
Htmltablerow TR = (htmltablerow) E. Item. findcontrol ("ID ");
// Custom attribute: the specific implementation of CSS is on the page, and the background only references
** Background code: TR. attributes ["class"] = ". ID in CSS ";

(3) throw an error: Throw new exception ("custom error type ");

5. instance:

Move_pic.aspx

 1 <% @ Page Language = "  C #  " Autoeventwireup = "  True  " Codebehind ="  Move_pic.aspx.cs  " Inherits = "  Move_pic.move_pic  " %> 2   3 <! Doctype HTML public "  -// W3C // dtd xhtml 1.0 transitional // en  "   "  Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd  " >4   5 <HTML xmlns = "  Http://www.w3.org/1999/xhtml  " > 6 <Head id = "  Head1  " Runat = "  Server  " > 7 <Title> </title> 8 <SCRIPT src ="  Scripts/jquery-1.4.1.js  " Type = "  Text/JavaScript  " > </SCRIPT> 9       10 </Head> 11   12 <Body> 13 <Form ID = "  Form1  " Runat = " Server  " > 14 <Div> 15       16 <Asp: objectdatasource id = "  Objectperformance1  " Runat = "  Server  "   17 Deletemethod = "  Delete  " Insertmethod = "  Insert  "   18 Oldvaluesparameterformatstring = "  Original _ {0}  " Selectmethod = "  Getdata  "   19 Typename = "  Move_pic.dal.dataset1tableadapters.t_userinfotableadapter  "  20 Updatemethod = "  Update  " > 21 <Deleteparameters> 22 <Asp: parameter name = "  Original_susername  " Type = "  String  " /> 23 </Deleteparameters>24 <Insertparameters> 25 <Asp: parameter name = "  Susername  " Type = "  String  " /> 26 <Asp: parameter name = "  Spassword  " Type = "  String " /> 27 <Asp: parameter name = "  Email  " Type = "  String  " /> 28 <Asp: parameter name = "  Age  " Type = "  Int32  " /> 29 <Asp: parameter name = "  Pic_url  " Type = "  String  " /> 30 </Insertparameters> 31 <Updateparameters> 32 <Asp: parameter name = "  Spassword  " Type ="  String  " /> 33 <Asp: parameter name = "  Email  " Type = "  String  " /> 34 <Asp: parameter name = "  Age  " Type = " Int32  " /> 35 <Asp: parameter name = "  Pic_url  " Type = "  String  " /> 36 <Asp: parameter name = "  Original_susername  " Type = " String  " /> 37 </Updateparameters> 38 </ASP: objectdatasource> 39   40 <Asp: repeater id = "  Repeater1  " Runat = "  Server  " Performanceid = "  Objectperformance1 " > 41 <Headertemplate> welcome to <Table id = "  Tableid  " > <Tr>  42 <Itemtemplate> <TD> 43  '  <% # Eval ("susername") %>  ' A2 = '  <% # Eval ("Age") %>  ' Width ="  100  "  ,  44 Height = "  150  " Src = '  Image/<% # eval ("pic_url") %>  ' /> </TD> 45 </Itemtemplate> 46 <Footertemplate> </tr> </table> welcome to visit </footertemplate> 47 </ASP: repeater> 48   49 <SCRIPT type = "  Text/JavaScript  " > 50           /*  $ ("IMG"). mousemove (function (e ){  51   $ ("# Susername"). Text ($ (this). ATTR ("A1 "));  52   $ ("# Age"). Text ($ (this). ATTR ("A2 "));  53  $ ("# Divnone" mirror.css ("TOP", e.pageydomain.css ("Left", E. pagex). Show ("slow ");  54   });  */  55           //  Dynamic Growth  56         /*  $ (Function (){  57   $ ("# IMG"). Click (function (){  58   // $ (This). animate ({"width": "+ = 300", "height": "+ = 300 "}); 59   $ (This). animate ({"width": "300", "height": "300 "});  60   // $ (This). ATTR ("width", "300"). ATTR ("height", "300 ");  61   });  62   });  */  63 $ ( "  # Tableid img  "  ). Mouseenter (function (){ 64 $ ( This ). Animate ({ "  Width  " : "  300  " , "  Height  " : "  300  " }, "  Slow "  );  65               //  $ (This). siblings (). animate ({"width": "150", "height": "300 "});  66               //  Exclude yourself  67 $ ( "  # Tableid img  " ). Not ($ ( This ). Animate ({ "  Width " : "  100  " , "  Height  " : "  150  " }, "  Slow  "  );  68   });  69 </SCRIPT> 70       71 </Div> 72 <Div style = "  Display: None  " Id = "  Divnone  " > 73 <P> name: <span id = "  Susername  " > </Span> </P> 74 <P> Age: <span id = "  Age  " > </Span> </P> 75 </Div> 76   77 </Form> 78 </Body> 79   80 </Html>

The database table is designed as follows:

 

 

 

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.