由于GridView要绑定到多个不同的表,所以只能用AutoGenerateColumns=true的方式
那在代码中如果取得绑定到该列的列名呢?protected void gv1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow gvRow = gv1.Rows[e.RowIndex];
    // 这里如何取得从第1列到最后1列的列名?
}

解决方案 »

  1.   

    目前我只能通过再读取一次数据源,根据数据源的列名顺序判断GridView的列名不过我觉得既然GridView能显示列名,就应该能读取出来才对吧
      

  2.   


    string Name = GridView1.HeaderRow.Cells[1].Text; //1为第1列名字,照此类推..
    Response.Write(Name);
    睡觉了~
      

  3.   


            for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
            {
                Response.Write(dv.HeaderRow.Cells[i]);
            }
      

  4.   

    不错,我一直使用Repeater,极少使用GridView这类控件
    学习了,谢谢
      

  5.   

    我上面说错了。
    string Name = GridView1.HeaderRow.Cells[0].Text; //0为第1列名字,照此类推.. 
      

  6.   

    设置BoundField属性,在HeadText中输入列名。