Here I have created sample that will help you out.
HTML
<div>
<asp:GridView ID="gvData" runat="server" AutoGenerateColumns="true" />
<br />
<asp:Button Text="Change Column Name" runat="server" OnClick="ChangeName" />
<br />
<br />
<asp:GridView ID="gvRenameData" runat="server" AutoGenerateColumns="true" />
</div>
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("A"),
new DataColumn("B"),
new DataColumn("C")
});
dt.Rows.Add("abc", "bbc", "ccc");
dt.Rows.Add("xyz", "yyz", "zzz");
ViewState["Data"] = dt;
gvData.DataSource = dt;
gvData.DataBind();
}
}
protected void ChangeName(object sender, EventArgs e)
{
DataTable dt = null;
if (ViewState["Data"] != null)
dt = (DataTable)ViewState["Data"];
gvRenameData.DataSource = RenameDataTableColumn(dt, "1", "2", "3");
gvRenameData.DataBind();
}
public static DataTable RenameDataTableColumn(DataTable sourceDataTable, params string[] names)
{
if (names.Length > sourceDataTable.Columns.Count)
{
throw new IndexOutOfRangeException("names parameter count must be equal or less than sourceDatatable column count");
}
for (int i = 0; i < names.Length; i++)
{
sourceDataTable.Columns[i].ColumnName = names[i];
}
return sourceDataTable;
}