如何更改GridView的列名

时间:2015-10-24 14:01:37

标签: c# asp.net gridview web-applications

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中所有数据的代码,但列名是跟随数据库的,如何更改列名?

2 个答案:

答案 0 :(得分:0)

datagridview 中使用查看,而不是直接显示,这样可以避免各种问题,请按照link进行操作。< / p>

答案 1 :(得分:0)

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";
        }
    }