为GridView 赋值:    GridView 都用BoundField 默认建的。     this.GVTheGet.Rows[0].Cells[0].Text = gl.rkdh;
     this.GVTheGet.Rows[0].Cells[2].Text = gl.th;
      this.GVTheGet.Rows[0].Cells[4].Text = gl.xfdw_dm;
     this.GVTheGet.Rows[0].Cells[5].Text = gl.dw_dm;
     this.GVTheGet.Rows[0].Cells[6].Text = gl.bz;
     this.GVTheGet.Rows[0].Cells[7].Text = gl.sl.ToString();会报超索引错误。 刚从winfrom转NET,习惯DataGridView 中这样赋值,然后报超索引的错的话,加一个
    DataGridView.Rows.Add();  
就可以了,但是GridView 貌似没有这个方法,求教怎么赋值啊?
.
C#GridView.Net

解决方案 »

  1.   

    Cells[x],这个超了吧,确认有那么多控件吗
      

  2.   


    this.GVTheGet.Rows[0].Cells[0].Text = gl.rkdh;
    this.GVTheGet.Rows[0].Cells[2].Text = gl.th;LZ你怎么直接从Cells[0]跳到Cells[2]了?你第一列和第三列之间的东西呢?
      

  3.   

    赋第一个的时候就超索引了,应该是Rows[0]超索引了,,所以问一下,GridView是否有累死Rows.Add() 的方法
      

  4.   

    还是在前台弄好,后台直接绑定gridview吧
      

  5.   

    this.GVTheGet.Rows[0].Cells[0].Text = gl.rkdh;
    this.GVTheGet.Rows[0].Cells[2].Text = gl.th;
    这样没错啊。
      

  6.   

    直接绑定数据源就可以了<asp:BoundField DataField="id" HeaderText="学号" />
    http://blog.csdn.net/liujun198773/article/details/5590164
      

  7.   


    索引超出范围。必须为非负值并小于集合大小。
    参数名: index断点进入的话,this.GVTheGet.Rows.Count 是0,因为没有行,所以我往里写的时候报错了。我就像知道怎么给它手动加一行。
      

  8.   

    <asp:BoundField DataField="id" HeaderText="用户ID" ReadOnly="True" />
    <asp:BoundField DataField="name" HeaderText="用户姓名" />
    <asp:BoundField DataField="sex" HeaderText="性别" />
    http://www.cnblogs.com/Ryan_j/archive/2010/10/04/1842038.html
      

  9.   

     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            var row = e.Row;
            row.Cells[0].Text = "a";
            row.Cells[1].Text = "b";
            row.Cells[2].Text = "c";
            row.Cells[3].Text = "d";
        }
    测试没问题