简体   繁体   中英

add specific columns from datatable to gridview asp.net

I am looking to return a datatable to a gridview, however I dont need all of the columns in the datatable in the gridview.

how would be the best approach to do this programatically?

my code at the moment is this

Dim dt As DataTable = New DataTable()
dt = GetValues()
gvContactList.DataSource = dt

The columns that I need to return are indexed as follows 0, 6, 7, 9

Any and all help would be very much appreciated.

Create a temporary datatable (that has columns you are intersted in ) and populate the temporary table with the rows from the actual table.

Now bind the grid with datasource as temp datatable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM