Aug 5 2006

Databinding Expressions in ASP.NET 1.1/2.0

Category: ASP.NET 2.0 - GeneralBil@l @ 07:47

A very common question on the ASP.NET forums is how to do expression databinding on the ASPX page.

The ASP.NET allows you to use 3 different binding expressions:

1- <% %>
You can use the above expression to execute some C#/VB.NET code as follows:

<% Response.Write("Hello World"); %>

Which will print out "Hello World" on the page.

2- <%# %>
This expression can be used to execute any property, collection, expression, or method result on the ASPX page.

  1. <%# CustomerID %> will print out the customer ID provided CustomerID is a public property/field.
  2. <asp:ListBox ... datasource='<%# studentArray %>' ... /> this will bind the ListBox to an array of students.
  3. Full Name: <%# (Student.FirstName + " " + Student.La   stName) %>
  4. Number of users online: <%# GetUserCount() %>

The main idea here is that, the expression within the <%# %> is only executed when Page.DataBind() is called.

3- <%= %>
This works the same as the above expression syntax with the difference that this syntax is executed on page load without the need to call Page.DataBind(). Similar to Response.Write().

hth,

Regards


Candidates for test 70-620 should have minimum one year of experience in the IT industry. They characteristically make available phone support at the tier-1 or tier-2 level in a broad range of environments, incorporating retail stores and the small organizations or enterprise environment. 1Y0-259 is a Citrix Presentation Server 4.5 administration test. SY0-101 is a CompTIA Security+ exam. Designing unified Cisco multilayer switched networks is the task which requires you to pass 642-812.

Tags:

Comments are closed