将数据放在gridview的第2行

时间:2011-07-15 21:12:59

标签: gridview foreach rows

我正在使用foreach循环将数据插入到这样的网格视图中。

foreach (GridViewRow _row in grvbillDetail.Rows)
{
    _row = text;
    _row = text;
    _row = int;
    _row = int;
}

如何在第一行打印一些数据,在第二行打印一些?

提前致谢!

1 个答案:

答案 0 :(得分:1)

GridViewRow.RowIndex是在此处访问您的行的关键。

试试这个。

foreach (GridViewRow _row in grvbillDetail.Rows)
{
    if(_row.RowIndex == 0)
    {
        //this is the first row. do whatever you want here
    }
    if(_row.RowIndex == 1)
    {
        //this is the second row. do whatever you want here
    }
    //_row = text;
    //_row = text;
    //_row = int;
    //_row = int;
}

顺便说一句,如果你只想访问第一行和第二行,可以这样做

GridViewRow firstRow = grvbillDetail.Rows[0] as GridViewRow;
GridViewRow secondRow = grvbillDetail.Rows[1] as GridViewRow;