'how to show datatable header to gridview header

I want to show the datatable header to gridview header. My datatable have dynamic header it may be changeable so i want to show that header as a gridview header. please help me to create it.



Solution 1:[1]

Set the GridView's AutoGenerateColumns property to true(what is the default).

You could also generate them manually with AutoGenerateColumns set to false:

   foreach (DataColumn col in dt.Columns)
   {    
       BoundField field = new BoundField();
       field.DataField = col.ColumnName;
       field.HeaderText = col.ColumnName;
       GridView1.Columns.Add(field);
   }
   GridView1.AutoGenerateColumns = false;
   GridView1.DataSource = tbl; //a DataTable of your choice
   GridView1.DataBind();

Solution 2:[2]

use this code before initializing datatable;

$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
 $.fn.dataTable.tables({ visible: true, api: true }).columns.adjust();
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Tahir FEYZIOGLU