在复选框中的GridView中删除多行 [英] delete multiple row in gridview in checkbox

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

问题描述

如何通过选择复选框并使用asp.net进行确认来删除gridview中的多行



这段代码给出了一个错误,我找不到异常:-

例外是:-(对象引用未设置为对象的实例.)

C#的敏锐代码是:-

how to delete multiple rows in gridview with checkbox selection and with confirmation using asp.net



this code give an error and i cannot find the Exception:-

the exception is:-(Object reference not set to an instance of an object.)

The C# sharp code is :-

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow gv in GridView1.Rows)
        {
            CheckBox arun = (CheckBox)gv.FindControl("arun");
            if (arun.Checked==true)
            {
                int res = Convert.ToInt32(GridView1.DataKeys[gv.RowIndex].Value);
                SqlDataSource1.DeleteParameters["userid"].DefaultValue = res.ToString();

                SqlDataSource1.Delete();

            }
        }
    }
}

推荐答案

我认为您忘记将ID设置为datakeyname


否则请尝试此代码



代替
i think u forgot to set id as datakeyname


otherwise try this code



Instead of
int res = Convert.ToInt32(GridView1.DataKeys[gv.RowIndex].Value);



试试



try

int res = Convert.ToInt32(GridView1.gv.Cells[1].Text);




//其中,cells [1]表示该ID字段的列位置




//where cells[1] means column position of that id field


何时将引发此错误,我使用:-int res = Convert.ToInt32(GridView1.gv.Cells [1] .Text);

错误:-System.Web.UI.WebControls.GridView不包含gv的定义

请为此帮我......
when it will throw this error i use :- int res = Convert.ToInt32(GridView1.gv.Cells[1].Text);

Error:- System.Web.UI.WebControls.GridView does not contain a definition for gv

please help me for this......


这篇关于在复选框中的GridView中删除多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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