Data Control (Repeater)

Source: Internet
Author: User

Show database-related data

The appearance is separated from the data.

Appearance code: use template to implement. (Head, foot, item, alternating item, delimiter template)

HeaderTemplate Header Template

FooterTemplate Foot Template

ItemTemplate Item Template

AlternatingItemTemplate Alternating Item Templates

SeparatorTemplate Separator Template

1. Add the Repeater control to the design page

2. Add a template to the <> source page

       <asp:repeater id="Repeater1 " runat="server">            <HeaderTemplate>                <ul>            </HeaderTemplate>            <ItemTemplate>                <li> <%# Eval ("Name")%></li>            </ItemTemplate>            < footertemplate>                </ul>            </FooterTemplate>        </asp:Repeater>

3. Binding data in a. cs file

            var query = context. Info;             = query;            Repeater1.databind ();

Repeater three ways to bind data in a template:

1. <%# Eval ("Property name or column name", "format")%>

    <%# Eval ("Birthday","{0:yyyy mm month DD day}")%>

2, <%# function name ()%>, function needs to be written in the. cs file beforehand and return a string. Such as:

     Public string Showsexname ()    {        bool sex = Convert.toboolean (Eval ("sex"));         return " male " " female " ;    }

3. If you are using an entity class (such as LINQ), you can extend the attribute to bind using <%# Eval ("extended attribute")%> in the template.

    <td><%# Eval ("nation1.name")%></td>

Data Control (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.