Adding data to a asp.net page with data bundles

Source: Internet
Author: User

If you are familiar with classic ASP, you will be familiar with the data binding syntax in ASP.net, even if the functions are not the same. The data-bound expression is the code in the middle of the <%# and%> in the ASPX file. It allows data to be bound to the controller, while also allowing binding properties, expressions, and the results of method calls on the page to be bound to the controller. While this feature is easy to use, it sometimes creates confusion when determining what content is allowed to bind and whether it has been used.

Data binding elements

When the DataBind method is invoked in the asp.net of the page, the data-binding expression is linked to the properties in ASP.net, the server control properties, and the data source. When you open the server-controlled tab or anywhere on the page, you can place the expression on the value of the attribute/numeric pair. All data-binding expressions, regardless of where they are placed, are contained in the <%# and%> characters.

When using a data controller (Repeater, DataGrid, and so on), the parameter of an expression is typically the column name of the data source. In any case, whenever it returns a value, any valid expression can be used. Similarly, the same syntax can be used for external list control. This includes displaying values or assembling controller properties on the page.

Container.DataItem is a DataItem alias for a particular detail at run time. It maps a separate detail from the data source, such as getting a row from a data query or getting a single element from a vector. The actual data type of the DataItem is determined by the data source. Therefore, when dealing with an integer vector, the DataItem is also integral type.

The following list reviews some of the vb.net syntax:

<%# Container.DataItem%>--return string vector

<%# Container.DataItem ("expression")%>--returns a specific field in the DataView container

<%# Container.DataItem.PropertyName%>--Returns property values for a specific string in the data source

<%# CStr (Container.DataItem.PropertyName)%>--returns the property value and converts it to a string form

When you use C #, the syntax is slightly different. The following list contains the C # code corresponding to the list above. Note that the basic syntax is consistent, but there is a change in the return of the property value and the conversion of the data type.

<%# Container.DataItem %>
<%# ((DataRowView)Container.DataItem)["PropertyName"] %>
<%# ((ObjectType)Container.DataItem).PropertyName %>
<%# ((ObjectType)Container.DataItem).PropertyName.ToString() %>

The syntax is compatible when you work with the properties and methods of a page. As long as the string value is returned, the syntax is exactly the same. The following list shows an example:

<%# PropertyName%>--Returns the page Horizontal property value

<asp:listbox id= "lstvalues" Datasource= ' <%# PropertyName%> ' runat= ' server ' >--returns the page-level property values that are bound to the data controller (vector, Set of objects, etc.)

<%# (objectname.propertyname)%>--Display Page Horizontal object property values

<%# methodname ()%>--display the value returned by the page method

Use the following syntax to use a single value on the page (properties and method returned values, and so on)

<%= Value%>

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.