开发者

Put data in 2nd row of a gridview

开发者 https://www.devze.com 2023-03-21 16:31 出处:网络
I am using a foreach loop to insert data into a gridview such as this. foreach (GridViewRow _row in grvbillDetail.Rows)

I am using a foreach loop to insert data into a gridview such as this.

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

How can 开发者_开发问答i make some of the data print on the first row and some print on the second row?

Thanks in advance!


GridViewRow.RowIndex is the key to access your rows here.

Try this.

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

By the way, if you want to access only the first and second row, do something like this

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号