如何使用复选框从gridview删除行? [英] how to delete a row from gridview using a checkbox?
本文介绍了如何使用复选框从gridview删除行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用复选框从gridview删除行.我没有使用任何数据库..如何在gridview
how to delete a row from gridview using a checkbox. I m not using any database ..how to delete a blank row in gridview
推荐答案
^ ]提供了一种简单的方法来帮助您开始.
此 [ http://csharpdotnetfreak.blogspot.com/2009/04/delete-multiple- rows-gridview-checkbox.html [
Deleting multiple Rows in GridView using Checkbox[^] provides an easy way to help you get started.
This[^] should be a help for you as well.
http://csharpdotnetfreak.blogspot.com/2009/04/delete-multiple-rows-gridview-checkbox.html[^] offers a fairly simple exmaple too.
这是我在我的页面之一中使用的代码.希望对您有所帮助.
我已经使用列表数组和会话来做到这一点.如果没有页面导航,您也可以使用viewstate.
this is the code i have used in one of my page. hope this helps.
I have used list arrays and sessions for doing this. u can use viewstate also if there is no page navigation.
DiabeticFields objDiabeticFields = new DiabeticFields();
List<DiabeticFields> diabList = new List<DiabeticFields>();
我使用了一个按钮 cmdDelete
.单击此按钮后,将触发以下事件
I have used one button cmdDelete
. After clicking on this button the following event will be fired
protected void cmdDelete_Click(object sender, EventArgs e)
{
diabList = (List<DiabeticFields>)(Session["DiabObject"]);
CheckBox chk = new CheckBox();
foreach (GridViewRow gvr in grdDocOrders.Rows)
{
chk = (CheckBox)(gvr.Cells[0].FindControl("chkSelect"));
if (chk.Checked == true)
{
diabList.RemoveAt(gvr.RowIndex);
}
Session["DiabObject"] = diabList;
if (diabList != null)
{
grdDocOrders.DataSource = diabList;
grdDocOrders.DataBind();
}
else
{
emptyGridFix();
}
}
}
DiabObject
包含gridview的所有行.无需在数据库中显示这些行..
the DiabObject
contains all the rows of the gridview.There is no need to present these rows in database..
这篇关于如何使用复选框从gridview删除行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文