当列具有单元格为空时,如何从datagridview中选择行 [英] how to select row from datagridview when column have cells is empty

查看:99
本文介绍了当列具有单元格为空时,如何从datagridview中选择行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

如果列中的单元格为空,如何从datagridview中选择行

我尝试了几个这样但没有工作

请帮助这个

Hi there !
how to select row from datagridview when column have cells is empty
I tried couple of this but nothing worked
Please help on this

private void selectrow()
       {
           int i;
           for( i=0 ;i<datagridview1 .rows="" .count="" mode="hold" />            {
               string row = dataGridView1.Rows[i].Cells["Name"].Value.ToString();
               if (row =="")
               {
                   sqlconn.Open();
                   string sqlquery = "select * from tbl... where id='" + dataGridView1.Rows[i].Cells["id"].Value.ToString() + "'";
                   SqlCommand sqlcmd = new SqlCommand(sqlquery, sqlconn);
                   SqlDataAdapter sqlda = new SqlDataAdapter(sqlcmd);
                   DataTable dt = new DataTable();
                   sqlda.Fill(dt);
                   dataGridView1.DataSource = dt;
                   sqlconn.Close();
               }
           }
       }

推荐答案

不检查空行在循环中。或许,获取所有数据行。然后使用if条件来检查行值。如果它为空,请获取datarow单元格名称并继续执行。
Don't check for empty rows in loop. Perhaps, get all the datarows. Then use if condition to check row value. If its empty, get the datarow cell name and go ahead and do your thing.


这篇关于当列具有单元格为空时,如何从datagridview中选择行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆