Asp.net datagridatagriget custom Columns

Source: Internet
Author: User

You only want to display the custom fields in the database tutorial. Some fields are not displayed. This is also a small question ~~~~ The implementation is as follows:

1: add the number of columns to be displayed on the datagridview design page, and assign the corresponding name:

 

2: Write the background code to bind the data source. The data source is bound to a able. Set the attribute of the automatically created column of the datagridview to false.


View sourceprint? 1 dataset ds = userinfobll. getalllist ();

2 // cancel Automatic column creation for datagridview1

3 this. datagridview1.autogeneratecolumns = false;

4 this. datagridview1.datasource = ds. tables [0];

3: Direct the datapropertyname attribute of the columns added on the design interface to the corresponding columns to be displayed in the database. The implementation is as follows:


View sourceprint? 1 // bind the datapropertyname attribute of the Custom column to the column of the table in the database

2 this. datagridview1.columns ["column1"]. datapropertyname = ds. tables [0]. columns [0]. tostring ();

3 this. datagridview1.columns ["column2"]. datapropertyname = ds. tables [0]. columns [1]. tostring ();

4 this. datagridview1.columns ["column3"]. datapropertyname = ds. tables [0]. columns [3]. tostring ();

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.