本文介绍了删除记录时如何刷新gridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!


我有一个gridview并且也包含复选框字段.如果单击复选框然后单击删除按钮,则删除相关记录.此删除功能正常工作.
-------------
问题
即使删除了记录,它也不会在gridview中受影响.已删除的记录仍然保留在gridview中.应该如何解决该问题?

谢谢.

--------------
受保护的void Page_Load(对象发送者,EventArgs e)
{
如果(!Page.IsPostBack)
{
var getAllContacts =来自dcon.contact_contactInfos中的c
选择新建{c.fName,c.lastName,c.title,c.accountName,c.officePhone,c.assignTo};

GridView1.DataSource = getAllContacts;
GridView1.DataBind();
}

}


受保护的void deleteContact_Click(对象发送者,EventArgs e)
{
for(int i = 0; i< gridview1.rows.count; 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 =" getallcontacts)
=" deletecontactaddress ="con.contact_contactInfos.Single(contact" =="> contact.cid == item.cid);
dcon.contact_contactInfos.DeleteOnSubmit(deleteContactAddress);
dcon.SubmitChanges();

}
}

}
}


I have a gridview and which contain checkbox field too.If the checkbox is clicked and then delete button click, relevent record is deleted.This delete function is working properly.
-------------
problem
Even though record is deleted,it does not affected in gridview.Deleted record is still remaining in the gridview.What will be the way that should I follow solve this problem?

Thank you.

--------------
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
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 deleteContact_Click(object sender, EventArgs e)
{
for (int i = 0; i<gridview1.rows.count; 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="" getallcontacts)
="" deletecontactaddress="con.contact_contactInfos.Single(contact" =="">contact.cid == item.cid);
dcon.contact_contactInfos.DeleteOnSubmit(deleteContactAddress);
dcon.SubmitChanges();

}
}

}
}

推荐答案


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();
}
}
}
}


这篇关于删除记录时如何刷新gridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 00:17