Where I can get column names if i flled gridview by DataSource dynamically?
OracleDataAdapter adapter = new OracleDataAdapter();
DataTable tableD = new DataTable();
tableD.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.SelectCommand = oracleCom;
adapter.Fill(tableD);
tableResults.DataSource = tableD.AsDataView();
tableResults.DataBind();
Where tableResults is GridView.
This code doesn’t work:
updatingAtributes += tableResults.Columns[i].HeaderText;
Columns property of GridView will be set if you configure the columns on GridView. If you are relying on default behavior of GridView to render columns by setting AutoGenerateColumns property to true, then the Columns collection is not set with any value. In such case, you will have to use the object that you used as DataSource of the GridView (which is the DataTable tableD in your case) to get the column name.