在asp.net的gridview中找到id [英] to find id in gridview in asp.net

查看:117
本文介绍了在asp.net的gridview中找到id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,
访问网格中的stateid时出现以下错误,错误是

索引超出范围.必须为非负数,并且小于集合的大小.
参数名称:索引"

错误发生在行
"to.StateId1 = Convert.ToInt32(GdState.DataKeys [row.RowIndex] .Value);"


sir,
i have following error when i am accessing the stateid in grid the error is

"Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index"

error occured at line
"to.StateId1 = Convert.ToInt32(GdState.DataKeys[row.RowIndex].Value);"


protected void btnDeleteState_Click(object sender, EventArgs e)
   {
       ClassMethods cm = new ClassMethods();
       ToContainer to = new ToContainer();
       int counter = 0;
       foreach (GridViewRow row in GdState.Rows)
       {
           CheckBox Chkbxstate = row.FindControl("chkchild") as CheckBox;
           if (Chkbxstate.Checked)
           {

               to.StateId1 = Convert.ToInt32(GdState.DataKeys[row.RowIndex].Value);//error at this line

               counter += cm.DeleteState(to);
           }
       }
       if (counter > 0)
       {
           lbldel.ForeColor = System.Drawing.Color.Blue;
           lbldel.Text = counter.ToString() + " States Deleted Successfully";
       }

       ShowGridState();

       //ClassMethods cm = new ClassMethods();

   }

请帮助我
谢谢问候
dnyaneshwar kawathe

please help me
thanx & regards
dnyaneshwar kawathe

推荐答案

foreach (GridViewRow row in GdState.Rows)
        {
            GdState.SelectedIndex = row.RowIndex;
            CheckBox Chkbxstate = row.FindControl("chkchild") as CheckBox;
            if (Chkbxstate != null && Chkbxstate.Checked)
            {

                to.StateId1 = Convert.ToInt32(row.SelectedValue);//error at this line

                counter += cm.DeleteState(to);
            }
GdState.SelectedIndex = -1;
        }


这篇关于在asp.net的gridview中找到id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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