Repeater multi-template implementation

Source: Internet
Author: User

Description: it is similar to dynamic things. Different Types use different templates, different styles, and different fields.

For example:

A certain person published the log "study every day"

A certain person posted a photo of Qinghai Lake.

XXXXX

XXXXX

XXXXX

 

(The above XXX is the image position)

Implementation: ① SQL: Associate the required data with a view to a table

② C # :( the most critical, provided by the fruit er http://nonlyli.cnblogs.com/, the key point is to put different templates with placeholer, and then remove unnecessary templates in the onitemcreated event)

< ASP: Repeater ID = "Rptlist" Runat = "Server" Onitemcreated = "Rptlist_created" >
< Itemtemplate >
< ASP: placeholder ID = "Recordtype1" Runat = "Server" >
< Li > <% # Eval ( " Name " ) %> Published logs <% # Eval ( " Title " ) %> </ Li >
</ ASP: placeholer >
< ASP: placeholder ID = "Recordtype2" Runat = "Server" >
< Li >
<% # Eval ( " Name " ) %> Posted Images <% # Eval ( " Title " ) %>
< IMG SRC = "<% # Eval (" Imgpath ") % > "/>
</ Li >
</ ASP: placeholer >
</ Itemtemplat >

 

Protected   Void Repeaterincluitemcreated ( Object Sender, repeateritemeventargs E)
{
If (E. Item. itemtype = Listitemtype. alternatingitem | E. Item. itemtype = Listitemtype. item)
{
Datarowview Dr = (Datarowview) E. Item. dataitem;
Control C = E. Item. findcontrol ( " Recordtype "   + Dr [ " Type " ]);
E. Item. Controls. Clear ();
E. Item. Controls. Add (C );
}
}

 

In fact, visible may be better.

 

Code < ASP: Repeater ID = "Rpttest" Runat = "Server" >
< Itemtemplate >
< ASP: placeholder ID = "Itemname" Visible = '<% # (String) eval ("type") = "name" % > 'Runat = "server">
Name: <% # Eval ( " Content " ) %>
</ ASP: placeholder >
< ASP: placeholder ID = "Itemage" Visible = '<% # (String) eval ("type") = "Age" % > 'Runat = "server">
Age: <% # Eval ( " Content " ) %>
</ ASP: placeholder >
</ Itemtemplate >
</ ASP: Repeater >

 

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.