asp.net dataGridView 擷取自訂欄

來源:互聯網
上載者:User

自己只想實現顯示資料庫教程中自訂的欄位,把一些欄位不顯示出來。這問題,也是小琢磨了一下~~~~實現如下:

1:在datagridview設計介面添加需要顯示的列數,並賦予相應的名稱:

 

2:編寫後台代碼,進行資料來源的綁定,綁定的是datatable。然後把datagridview的自動建立列的屬性設定為false。


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

2 //取消 datagridview1 的自動建立列 

3 this.datagridview1.autogeneratecolumns = false; 

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

3:將設計介面添加的列的datapropertyname屬性指向資料庫中要顯示的相應列,實現如下


view sourceprint?1 //把自訂的列的datapropertyname屬性綁定到資料庫中表的列 

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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.