Template using Repeater

xiaoxiao2021-03-06  13

.NET FX provides a method that uses template to control the Repeater's display at the program runtime.

I will not say more here, I can see the relevant information in MSDN. (Oh, I didn't do it.

)..

In fact, the Private Void LC_DATABINDINDING (Object Sender, Eventargs E) function, when the data in DataSource is backed, each bind is called, and we call this function once, we will complete the dynamic modification pattern through customization of this function: )

Here is the implementation of the code:

///

///

Datacontrolertype

///

public

ENUM

DataControlrtype {

///

///

Repeater

///

REPEATER,

///

///

Datalist

///

DataList,

///

///

DataGrid

///

DataGrid}

//

Public Delegate Void DataBinder (Object Container, Litral LC);

///

///

DataBinder Handler.

///

public

Delegate

Void

TemplatedataBinder

Object

Container, Litral LC,

String

ColumnNames;

///

///

Summary Description for Template.

///

public

Class

DataTemplateItem: itemplate {

Private

ListiteMType Templattype;

Private

String

[] columnnames

=

NULL

;

Private

Datacontrolrtype control;

public

TemplatedTabinder MyDataBinder

=

NULL

;

///

///

Constructor

///

///

///

///

public

DataTemplateItem

String

[] ColumnNames, ListItemType TemplateType, Datacontrolertype ControlType) {Templattype

=

TemplateType; ColumnNames

=

ColumnNames; ControlType

=

ControlType;

///

///

///

///

////

///

///

public

DataTemplateItem

String

[] ColumnNames, ListItemType TemplateType, Datacontrolertype ControlType, TemplatedataBinder DataBinder) {MyDataBinder

=

DataBinder; TemplateType

=

TemplateType; ColumnNames

=

ColumnNames; ControlType

=

ControlType;

///

///

///

///

///

public

DataTemplateItem (ListItemType TemplateType) {TemplateType

=

TemplateType; ControlType

=

ControlType;

///

///

///

///

///

///

public

DataTemplateItem (ListIntrolType Templatype, TemplatedATABINDER DATABINDER) {MyDataBinder

=

DataBinder; TemplateType

=

TemplateType; ControlType

=

ControlType;

public

Void

Instantiatein (System.Web.ui.Control Container) {Litral LC

=

New

Literal ();

IF

(MyDATABINDER)

==

NULL

) {

Switch

(Templattype) {

Case

ListitemType.Header: lc.text

= "

"

;

Foreach

(

String

i

in

Columnnames) {lc.text

=

"

"

}

Else

{MyDataBinder (Container, LC, ColumnNames);}}} In the code above, I define a delegate templatedataDatabase to control the display output. Use the code:

this.Repeater1.DataSource = reader; this.Repeater1.HeaderTemplate = new ShowDataTemplate (ListItemType.Header, DataControlerType.Repeater, new ShowDataTemplateDelegate (TempHeader)); this.Repeater1.FooterTemplate = new ShowDataTemplate (ListItemType.Footer, DataControlerType.Repeater); this.Repeater1.ItemTemplate = new ShowDataTemplate (ListItemType.Item, DataControlerType.Repeater, new ShowDataTemplateDelegate (TempItem)); this.Repeater1.AlternatingItemTemplate = new ShowDataTemplate (ListItemType.AlternatingItem, DataControlerType.Repeater, new ShowDataTemplateDelegate (TempAlternatingItem)); this. Repeater1.DataBind (); private void TempHeader (object container, Literal lc, string [] columnNames) {int index = -1; lc.Text = "

"

i

"

"

} Lc.text

=

"

"

;

Break

;

Case

ListItemType.footer: lc.text

=

"

"

;

Break

;

Case

ListItemType.Item:

Case

ListitemType.alternatingItem: lc.databinding

=

New

EventHandler (LC_DATABIND);

Break

}}

Else

{

Switch

(Templattype) {

Case

ListitemType.Header:

Case

ListItemType.Footer: MyDataBinder (Container, LC,

THIS

.columnnames;

Break

;

Case

ListItemType.Item:

Case

ListitemType.alternatingItem: lc.databinding

=

New

EventHandler (LC_DATABIND);

Break

:}} Container.Controls.Add (LC);

Private

Void

LC_DATABINDINDING

Object

Sender, Eventargs E) {Literal LC

=

(LITERAL) SENDER; Object Container;

IF

(ControlType

==

Datacontrolertype.repeater) {Container

=

(RETERITEM) lc.namingcontainer;}

Else

IF

(ControlType

==

Datacontrolertype.DatAlist) {Container

=

DatalistItem) lc.namingcontainer;}

Else

//

IF (ControlType == ControlType.DataGrid)

{Container

=

DataGridItem) lc.namingcontainer;}

IF

(MyDATABINDER)

==

NULL

) {

FOREACH

String

i

in

Columnnames) {lc.text

=

"

"

Lc.Text

=

DataBinder.eval (Container,

"

DataItem.

"

i); lc.text

=

"

"

} Lc.text

=

"

"; foreach (String i in columnnames) {INDEX ; if (i == "ID") {Continue;} lc.text = "";

转载请注明原文地址:https://www.9cbs.com/read-48075.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.034, SQL: 9
" columnShows [index] "";} lc.text = "";} Private void Tempitem (Object Container, Literal LC, String [] ColumnNames) {string id = ""; Lc.text = "