在网格视图中删除的问题 [英] problem in deleting in grid view

查看:74
本文介绍了在网格视图中删除的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网格视图,其中我想用复选框选择多行,我想删除那些行,但它显示错误

Quote:

指数超出范围。必须是非负的且小于集合的大小。

参数名称:index



这里的代码请帮帮我



 protected void btnDelete_Click(object sender,EventArgs e)
{

foreach(GridViewRow gvrow in Grid.Rows)
{

CheckBox chkdelete =(CheckBox)gvrow.FindControl(chkdelete);

if(chkdelete.Checked)
{
int usrid = Convert.ToInt32(Grid.DataKeys [gvrow.RowIndex] .Value.ToString());
objUsers.DeleteParameters [Id]。DefaultValue = usrid.ToString();
objUsers.Delete();


BindEmployeeDetails();

}
}
}
}

解决方案

< blockquote>

  void  DoSomething()
{
foreach (GridViewRow gvrow in Grid.Rows)
{
List< int> lst = new List< int>();
CheckBox chkdelete =(CheckBox)gvrow.FindControl( chkdelete);

if (chkdelete.Checked)
{
int usrid = Convert.ToInt32(Grid.DataKeys [gvrow.RowIndex] .Value.ToString());
lst.Add(usrid);
objUsers.DeleteParameters [ Id]。DefaultValue = usrid.ToString();
objUsers.Delete();
}
}

BindEmployeeDetails();
}


任何人都能帮帮我吗?请.............................

I have grid view in which i want to select the multiple rows with the check box and i want to delete that rows but it showing an error

Quote:

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


here is the code please help me

protected void btnDelete_Click(object sender, EventArgs e)
       {

           foreach (GridViewRow gvrow in Grid.Rows)
           {

               CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");

               if (chkdelete.Checked)
               {
                   int usrid = Convert.ToInt32(Grid.DataKeys[gvrow.RowIndex].Value.ToString());
                   objUsers.DeleteParameters["Id"].DefaultValue = usrid.ToString();
                   objUsers.Delete();


                   BindEmployeeDetails();

               }
           }
       }
   }

解决方案

void DoSomething()
{
    foreach (GridViewRow gvrow in Grid.Rows)
    {
        List<int> lst = new List<int>();
        CheckBox chkdelete = (CheckBox)gvrow.FindControl("chkdelete");

        if (chkdelete.Checked)
        {
            int usrid = Convert.ToInt32(Grid.DataKeys[gvrow.RowIndex].Value.ToString());
            lst.Add(usrid);
            objUsers.DeleteParameters["Id"].DefaultValue = usrid.ToString();
            objUsers.Delete();
        }
    }
 
    BindEmployeeDetails();
}


can any body help me? Please.............................


这篇关于在网格视图中删除的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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