Asp.net--gridview Control binding Data

Source: Internet
Author: User

Asp. NET provides a number of data server controls for displaying table data from a database in a Web page, one of which is the GridView control. This control is almost the same as the DataGridView control we have learned, so we are not unfamiliar with the GridView control, so let's take a brief look at its use.

Front desk:

Locate the GridView control in the Toolbox and drag it to the code editing area.

First step, enter the design interface, there is a right black triangle above the GridView control, click this button, select Edit Column,


In the second step, remove the tick in front of the auto-generated field and choose BoundField based on the binding content.


The third step is to set the title name HeaderText and the bound field name DataField.


Fourth step, if you want to uniformly set the style of each row of the form, choose to convert each field to TemplateField.


above when these steps are set up, the HTML code is automatically generated.         

    <div id= "Newnews" class= "commonfrm" > 


Background code:         

protected void Page_Load (object sender, EventArgs e)    {        if (! Page.IsPostBack)        {            //First entry to this page            newsmanager nm = new Newsmanager ();            Binding Latest News            Gvnewnews.datasource = nm. Selectnewnews ();            Gvnewnews.databind ();            Bind hotspot News            Gvhotnews.datasource = nm. Selecthotnews ();            Gvhotnews.databind ();        }    }
Compare:

In the beef Brisket news release system, a control that binds data, called the Repeater control, does not have its own built-in rendering capability, meaning that users must create templates to provide the layout of repeater controls, and ItemTemplate to define templates.

The GridView control is more powerful and more flexible than the repeater control, and is able to customize the style of each column of each row, but there is a downside to generating extra code that is too much to be considered.

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.