After the data source is bound, the events triggered by the repeater at the time of creation, and the value of a field called in the CS File

Source: Internet
Author: User
-

Because I switched from ASP to learning. net, a lot of ideas have to follow ASP, but in my just getting started, I found that the display data is generally bound to a dataset control (such as, repeater ), displaying Data in repeater is also easy. You only need to write <% # eval ("field name") %> In itemtemplate.
But sometimes we need to dynamically attach the field content to a container (such as label) in the CS file, but in the background, enter label. TEXT = eval ("field name") is not acceptable
There are two problems:
1. The Labe in repeater is in the CS file, so it cannot be directly attached with a value (the value retrieved from the database)
2. eval ("field name") cannot be written.

What should we do?

In fact, you can use the following method to attach a value to label1 (belowCodeE is the transfer parameter in the event, which is generated by the system)

 

If (E. Item. itemtype = Listitemtype. Item | E. Item. itemtype = Listitemtype. alternatingitem)
{
(Label) E. Item. findcontrol ( " Label1 " ). Text = (Datarowview) E. Item. dataitem). Row [ " Adate " ]. Tostring ();
}

 

---------------------------------------------

Another problem is that in ASP, all records are displayed in the HTML loop by ourselves. We can add a lot of code to control the loop.
In. net, the database content is basically displayed by the control itself. We do not need to write loop Code such as ASP in. Net:

< %
Do   While   Not Rs. EOF

Rs. movenext
loop
% >

what if we need to add the control code in the loop like asp?
we can use the itemcreated event. In repeater, this event is automatically executed every time a record is displayed.

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.