hi

i want to delete multiple report in grid view and i am facing some problem please help me as i am new to Asp.net.

 protected void LinkButton1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox cb = (CheckBox)row.FindControl("chkSelect");
            if (cb.Checked)
            {
                int rid = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                SqlDataSource1.DeleteParameters["id"].DefaultValue = rid.ToString();
                SqlDataSource1.Delete();
            }
            }
    }

Just make sure that "DataKeyNames" property is set with any filed id(i.e EmployeeID, CustomerID etc). When you have set DataKeyNames property, Gridview control automatically create DataKey object for each row.

Here, It may be possible that you haven't set DataKeyNames and you are trying to retrieve the DataKey for a particualr row.

int rid = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);

So if not set then Set it with Gridview tag in design.

Let us know if it will not solve your problem.

hi

i want to delete multiple report in grid view and i am facing some problem please help me as i am new to Asp.net.

protected void LinkButton1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkSelect");
if (cb.Checked)
{
int rid = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
SqlDataSource1.DeleteParameters["id"].DefaultValue = rid.ToString();
SqlDataSource1.Delete();
}
}
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.