i have created a method named bindGrid() and called it in page load and on delete.
It is all clear that when u have deleted the record that means your collection and database has changed so it is always better to fetch the data again same applies while updating and inserting the records...
protected void bindGrid()
{
var getAllContacts = from c in dcon.contact_contactInfos
select new{ c.fName,c.lastName,c.title,c.accountName,c.officePhone,c.assignTo};
GridView1.DataSource = getAllContacts;
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
bindGrid();
}
}
protected void deleteContact_Click(object sender, EventArgs e)
{
for (int i = 0; i
{
CheckBox cb=(CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if ((cb != null)&&(cb.Checked))
{
var getAllContacts = from c in dcon.contact_contactInfos
select new { c.cid };
foreach (var item in getAllContacts)
{
var deleteContactAddress = con.contact_contactInfos.Single(contact =>contact.cid == item.cid);
dcon.contact_contactInfos.DeleteOnSubmit(deleteContactAddress);
dcon.SubmitChanges();
bindGrid();
}
}
}
}