try this code
public void deleteItems(Object src, EventArgs e)
{
DataTable myTable = (DataTable)Session["myTable"];
int deleted = 0, knt = myGrid.Items.Count;
if (((HtmlInputCheckBox)myGrid.Controls[0].Controls
[0].FindControl("cbAll")).Checked)
{
myTable.Clear();
deleted = knt;
}
else
{
DataRowCollection myRows = myTable.Rows;
foreach (DataGridItem item in myGrid.Items)
{
HtmlInputCheckBox cbItem = (HtmlInputCheckBox)
item.FindControl("cbItem");
if (cbItem.Checked)
{
string supplierID = myGrid.DataKeys
[item.ItemIndex].ToString();
DataRow thisRow = myRows.Find(supplierID);
if (thisRow != null)
{
string strdel = "Delete from dg where fid = "
+ supplierID + " ";
SqlConnection con = new SqlConnection
(ConfigurationManager.AppSettings["dst"]);
SqlCommand cmd = new SqlCommand(strdel, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
myRows.Remove(thisRow);
}
}
deleted++;
}
}
Session["myTable"] = myTable;
myGrid.DataSource = Session["myTable"];
myGrid.DataBind();
myGrid.Visible = (myGrid.Items.Count > 0);
}
On Mar 31, 2:09 pm, Jeena Ajiesh <[email protected]> wrote:
> Hi all,
> I had currently some rows in datagrid,,wen i click deleteall button all the
> records displayed in grid should be deleted..
> How can i do this?
> I tried to take the count of rows and delete it using delete function
> Eg: Grid1.DeleteRow(i) --- this is in While loop.
>
> But it failed. i think i had wrongly coded.
> Can anyone help me out this situation?
>
> --
> ****************
> Regards,
> ♪♥♫♥Ĵєєήǎ ♫♥♪♥
> Email: [email protected]
> [email protected]
> [email protected]