首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

dataGridView1遍历的有关问题

2013-12-05 
dataGridView1遍历的问题c#的dataGridView1如何遍历,并且返回行号?目前是不要绑定DataSet。我这样遍历出现

dataGridView1遍历的问题
c#的dataGridView1如何遍历,并且返回行号?

目前是不要绑定DataSet。

我这样遍历出现异常:

if (this.dataGridView1.Rows.Count > 0)
{
    for (int j = 0; j < this.dataGridView1.Rows.Count; j++)     
    {
        if ((this.dataGridView1.Rows[j].Cells[0].Value.ToString()=="XX") &&
                                        (this.dataGridView1.Rows[j].Cells[1].Value.ToString()=="YY"))
        {
           indx = j;
           return;
        }
    }
} 楼主这个完全可以在在js中解决。 
var number = 0;
            var gdview = document.getElementById("<%=gridview.ClientID %>");
            for (var i = 0; i < gdview.rows.length; i++) {
                if (gdview.rows(i).cells(0).innerText == "XX" & gdview.rows(i).cells(1).innerText == "YY") {
                    number++;
                }
            }
            return number;

热点排行