Click here to Skip to main content
15,913,115 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I want to delete multiple report in grid view and i am facing some problem please help me .
C#
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();
     }
   }
}
Posted
Updated 5-Sep-10 23:51pm
v3

Not very clear what are your trying to do here:
C#
int rid = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);      
SqlDataSource1.DeleteParameters["id"].DefaultValue = rid.ToString();      
SqlDataSource1.Delete();


Looks like you ware trying to remove the whole row that were selected. Don't know where is it related to reports!

If you are trying to remove rows, then I doubt it is not the correct way. Use DEBUGGER and you will see that once you delete a particular row then the row counts reduces and thus the for loop goes out of existing row counts.
 
Share this answer
 
use debugger [use break points and debug] . you can solve this problem yourself very easily.
 
Share this answer
 
may by something wrong with this
Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);

code snippet.
The count of Datakeys is 0 may be .
Have you set the datakey to gridview correctly?
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900