I am using ASP.NET 4.0 C# and am trying to programmatically set the Header Text for the GridView on my page. I am getting an Index was out of range error and can't figure out what I am doing wrong. Here is the GridView on my page:
<asp:GridView ID="gvWarnings" runat="server">
And here is the code where I am trying to set the HeaderText:
gvWarnings.DataSource = dtWarnings;
gvWarnings.CellPadding = 3;
gvWarnings.CellSpacing = 3;
gvWarnings.Columns.HeaderText = "Warning";
gvWarnings.Columns.HeaderText = "Date";
gvWarnings.Columns.HeaderText = "Title";
dtWarnings is a datatable with 3 columns in it.
Any help is greatly appreciated!