Mobile Project Development notes (container. dataitem extension)

Source: Internet
Author: User

A itemtemplate of a repeate control is used in the project to nest a gridview. In this way, the outer repeate control is first bound to the data binding, and itemdatabound () is used in the repeate control () event to bind the gridview control.

Extract the following model from the project: see repeater nesting A gridview control.

<Asp: repeater runat = "server" id = "repbalanceaudit" onitemdatabound = "repbalanceaudit_itemdatabound">
<Headertemplate>

</Headertemplate>
<Itemtemplate>
<% # Databinder. eval (container. dataitem, "a_status") %>
<Asp: gridview runat = "server" id = "dgview">
<Columns>
<Asp: templatefield>
<Itemtemplate>
<% # Databinder. eval (container. dataitem, "B _status") %>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>
</Itemtemplate>
<Footertemplate>

</Footertemplate>
</ASP: repeater>

The <% # eval ("B _status") %> bound to itemtemplate IN THE dgview (above) of the gridview control must be changed. Changed to the data source field "a_status" bound to repeate,

However, the data source pointed to by the gridview does not contain the "a_status" field. It must be bound to a field in the parent data source. How can I write this binding expression?

After constantly trying and searching materials, I finally found the Writing Method of this nested binding expression:

<% # Databinder. eval (repeateritem) (gridviewrow) container). Parent). dataitem, "a_status") %>

 

Let's analyze the meaning of the above Code:

1. First, convert the iner to the gridviewrow object, because the current container indicates that the row of the gridview is gridviewrow.

2. Then (gridviewrow) container). Parent indicates to obtain the parent level of the current row, that is, the type is childtable object. Because a gridview contains childtable, there are many gridviewrow objects.

3. (gridviewrow) container). Parent. parent is the current gridview control, that is, the dgview object.

4. (gridviewrow) container). Parent. Parent. parent is the parent control of the current gridview control. It is repeateitem.

5. Finally, we need to forcibly convert this object into a repeateitem object. Find its a_status field.

According to the above code analysis, it is easier to access fields in the parent (Multi-Level) data source.

Below are some common writing methods for sharing with friends:

For nested Repeaters:

<% # Databinder. eval (system. Web. UI. webcontrols. repeateritem) container. Parent. P ð arent). dataitem, "fieldname") %>

For nested repeater/gridview \

<% # Databinder. eval (repeateritem) (gridviewrow) container). Parent). dataitem, "fieldname") %>

For repeater/gridview

<% # Databinder. eval (repeateritem) (gridviewrow) container). Parent). dataitem, "fieldname") %>

 

In addition, I will explain some other data binding formats: This program is often used when binding data: <% # databinder. eval (container. dataitem, "XXXX") %> or <% # databinder. eval (container, "dataitem. XXXX ") %>

. NET 2.0 has a new syntax: <% # eval ("XXXX") %> which is not very common:

<% # (Datarowview) container. dataitem) ["XXXX"] %>

Microsoft says this method is more efficient than the above two methods.

Remember to import the namespace system. Data on the front-end page. Otherwise, an error message is generated.

<% @ Import namespace = "system. Data" %>

 

Finally, I hope my friends can give me some comments. If you have any questions or errors, please kindly advise.

 

Charles Chen

MSN: Charles.C.Chen@newegg.net

Email: gotosunny@msn.com

 

 

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.