删除网格视图中的行而不影响数据库 [英] Delete row in a gridview without affecting Database
本文介绍了删除网格视图中的行而不影响数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从gridview中删除一些行而不影响数据库。所以我在代码项目本身看到的很多例子。但是下面代码的问题只是在第0个位置可以删除。但我想删除点击位置本身的行。任何人都可以提出任何建议吗?
以下是我的代码: -
Hi,
Iam trying to delete some rows from gridview without affecting the database.So many examples I saw in the code project itself.But the problem with the below code is only the row in the zeroth position can delete.But I want to delete the row in the click position itself.Can anyone suggest any idea?
Below is my code:-
protected void DeleteDemandSlabOnclick(object sender, EventArgs e)
{
DataTable demandSlabList;
if (txtbxTariff.Text.Contains("HT") == false)
InitializeFixedChargeTable(out demandSlabList);
else
InitializeDemandChargeTable(out demandSlabList);
foreach (GridViewRow Row in SlabsGrid.Rows)
{
DataRow row = demandSlabList.NewRow();
row[0] = Row.Cells[0].Text;
row[1] = Row.Cells[1].Text;
row[2] = Row.Cells[2].Text;
demandSlabList.Rows.Add(row);
}
if (demandSlabList.Rows.Count > 0)
{
demandSlabList.Rows.RemoveAt(0);
SlabsGrid.DataSource = demandSlabList;
SlabsGrid.DataBind();
}
}
推荐答案
总是做坏事。
你可以找到rowindex总是在你的GridView RowCommand
事件中。
试试这个:
Bad practice always.
You can find the rowindex always in yourGridView RowCommand
event.
Try this:
GridViewRow gvr = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int RowIndex = gvr.RowIndex;
现在您可以使用 RemoveAt
功能删除该行。您需要传递索引
作为此 RowIndex
。
--Amit
Now you can delete the row using RemoveAt
function. You need to pass Index
as this RowIndex
.
--Amit
这篇关于删除网格视图中的行而不影响数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文