DataGrid Web controls (1)

Source: Internet
Author: User

DataGrid Web controls (1)

This article is the first part of a series of articles about using the DataGrid Web control. The ASP. Net DataGrid Web control can display database information in HTML tables with powerful functions. In the simplest case, the DataGrid displays the HTML table framework. However, it can be enhanced to display rich user interfaces. It can be sorted by database columns or even paginated database results! All these interesting topics will be covered in a series of future articles.
Retrieving table information from a database and displaying it in an HTML table is one of the most common tasks in traditional ASP programming. In traditional ASP programming, the above functions need to be implemented through multi-line intertwined HTML and code. The following prototype code shows the common form of the Code.
Create Database Connection
Populate a recordset based on some SQL query
Output the HTML table header (<table...>)
Loop through the recordset
Emit the HTML for a table row
...
Emit the HTML table footer (</table>)

If you are an ASP developer, you have also compiled the above Code many times. One of the advantages of ASP. Net is that it contains many Web controls. These Web controls that generate HTML provide a programmable interface that allows developers to separate code and content and use HTML entities as objects in code. That is to say, if we need to display some HTML content through ASP. Net, We will write the following code:
<Script language = "vb" runat = "server">
Sub Page_Load (sender as Object, e as EventArgs)
LblMessage. Text = "Hello, World! "
End sub
</Script>
<Asp: label runat = "server" id = "lblMessage"/>
Here, the lblMessage Web control with the runat = "server" attribute (similar to the HTML Tag) is placed in HTML. Then, in the Page_Load event handler (this event handler is called every time the page is loaded), the Text attribute of lblMessage is set to "Hello World ". The use of Web controls achieves the separation of code and content. In traditional ASP, <% = "Hello, World! "%> The same effect can be achieved only when an appropriate location is placed in HTML.

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.