GridView列标题修改,GridView如何改变列标题?

GridView列标题修改成自己想要的

用GridView.Columns[0].HeaderText = "", 行不通

到网上找了下,应该是先绑定,再用GridView.HeaderRow.Cells[n]

foreach (DataGridViewColumn col in this.dataGridView1.Columns)
            {
               
string columnname = col.HeaderText;
            }

protected void GridView1_DataBound(object sender, EventArgs e)
    {
       
//列数
        int count = this.GridView1.HeaderRow.Cells.Count;
       
for (int i = 0; i < count; i++)
        {
           
string oldValue = this.GridView1.HeaderRow.Cells[i].Text;
           
if (oldValue == "UserName")
            {
               
this.GridView1.HeaderRow.Cells[i].Text = "用户名";
            }
           
else if (oldValue == "Order")
            {
               
this.GridView1.HeaderRow.Cells[i].Text = "订单";
            }
           
else
            {
               
this.GridView1.HeaderRow.Cells[i].Text = "其他";
            }
        }
           
    }


类别: gridview技巧  查看评论

你可能感兴趣的:(GridView)