Use of the C#repeater control

Source: Internet
Author: User

First, the use of repeater

Used to display data

Second, the use of repeater steps

Step1: Drag a Repeater control into the Web page. In the background code, specifying its data source requires a list generic collection.

 Public Partial class query:system.web.ui.page{    protectedvoid Page_Load (object  sender, EventArgs e)    {        new Fruitda ().  Select();        Repeater1.databind ();    }}

Step2. Edit the column name in the source code, specifying the property name of the data that needs to be displayed.

Run results

View Source code

Tips:

Repeater doesn't show anything in the Web page, it just passes the text data to the Web page. Is the same as the literal control.

Third, Hyperlink transfer data

Add an event to a new page

protected void Page_Load (object  sender, EventArgs e)    {        Response.Write (request["Ids " ]);     }

Run results

Click on "Pineapple"

Tip: When you transfer data with a hyperlink, you can see the URL change in the status bar below when the mouse is over the hyperlink. You can also see the difference in the address bar of a new page that accepts data.

Iv. Comprehensive Application

㈠ displaying data in a Web page in tabular form

Essence: Use the Repeater control to spell the string.

Run results

㈡ the use of alternating item labels <AlternatingItemTemplate>.

     <ItemTemplate>                <TR>                    <TDbgcolor= "Blue"><%#Eval("Ids") %> </TD>                    <TD><%#Eval("Name") %></TD>                </TR>            </ItemTemplate>            <AlternatingItemTemplate>                    <TDbgcolor= "Green"><%#Eval("Ids") %> </TD>                    <TD><%#Eval("Name") %></TD>            </AlternatingItemTemplate>

Run results

When the data is displayed, the item label and alternating item label are executed alternately, the item label is executed first, and the alternating item label is executed.

㈢ additions and deletions to search

Step1. Transferring data to a new web page

<ItemTemplate>                <TR>                    <TDbgcolor= "Blue"><%#Eval("Ids") %> </TD>                    <TD><%#Eval("Name") %></TD>                    <TD><ahref= "Delete.aspx?" ids=<% #Eval ("Ids ")%>The > Delete</a><a>Modify</a> </TD>                </TR>            </ItemTemplate>

Step2. Receives data from a hyperlink in a new page load event, calls the delete data function based on that data, and then returns to the original page.

protected void Page_Load (object  sender, EventArgs e)    {        Response.Write (request["Ids " ]);         New FRUITDA (). Delete (request["Ids"]);        Response.Redirect ("query.aspx");    }

Run the result, click Delete after "Pineapple",

Before clicking,

When clicked,

Because the page loading speed, so do not see the loading of the deleted page, the original page seems to have never left.

Use of the C#repeater control

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.