如何更改GridView的列名
本文关键字:GridView 何更改 | 更新日期: 2023-09-27 18:19:14
con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;Data Source=|DataDirectory|'database.mdb");
com = new OleDbCommand("Select * from testing", con);
con.Open();
OleDbDataReader reader;
reader = com.ExecuteReader();
GridView1.DataMember = "testing";
GridView1.DataSource = reader;
GridView1.DataBind();
reader.Close();
con.Close();
这是代码查看所有数据到GridView,但列名是跟随数据库,我怎么能改变列名?
testdgv.Columns[0].HeaderText = "Date";
或
void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "Name";
e.Row.Cells[1].Text = "City";
}
}