错误:“索引超出范围”在GridView中 [英] error :"index was out of range" in GridView

查看:108
本文介绍了错误:“索引超出范围”在GridView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个gridview,我想得到SELECT列值,如果它是真的那么得到ID列值但我得到错误:索引超出范围。必须是非负的并且小于<的大小

集合

我的代码:

I have a gridview,I want to get SELECT column value and if it was true then get ID column value but i got the error :"index was out of range. must be non-negative and less than the size of
the collection "
my code:

private void GrdSign_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewSelectedRowCollection rows = GrdSign.SelectedRows;
            if (Convert.ToBoolean(rows[0].Cells["Select"].Value))
            {
                signIDs += (string)rows[0].Cells["ID"].Value.ToString()+"#";
            }
        }

推荐答案

试试



Try

if(rows[0].Cells["Select"].value != string.Empty && rows[0].Cells["Select"].value != null)
{
if (Convert.ToBoolean(rows[0].Cells["Select"].Value))
            {
                signIDs += (string)rows[0].Cells["ID"].Value.ToString()+"#";
            }
}


这篇关于错误:“索引超出范围”在GridView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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