asp.net dataGridView get custom columns

Source: Internet
Author: User

I just want to implement the custom fields in the show database tutorial and put some fields out of the display. This problem, but also small pondering a little ~ ~ ~ To achieve the following:

1: Add the number of columns you want to display in the DataGridView design interface and give the appropriate name:

2: Write the background code, the data source binding, binding is a DataTable. Then set the DataGridView property of the automatically created column to False.


View sourceprint?1 DataSet ds = Userinfobll.getalllist ();

2//Cancel dataGridView1 automatic creation column

3 This.datagridview1.autogeneratecolumns = false;

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

3: The DataPropertyName property of the column added to the design interface points to the corresponding column to be displayed in the database, as follows


View sourceprint?1//Bind the DataPropertyName property of the custom column to the columns 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.