将数据放入 gridview 的第二行

发布于 2024-11-25 06:33:49 字数 242 浏览 3 评论 0原文

我正在使用 foreach 循环将数据插入到 gridview 中,如下所示。

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

我怎样才能使一些数据打印在第一行,一些数据打印在第二行?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瞳孔里扚悲伤 2024-12-02 06:33:50

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文