如何从GridView中删除一行?
如何从 GridView 中删除特定行。
我编写了以下代码。 但这不起作用...
DataRow dr = dtPrf_Mstr.NewRow();
dtPrf_Mstr.Rows.Add(dr);
GVGLCode.DataSource = dtPrf_Mstr;
GVGLCode.DataBind();
int iCount = GVGLCode.Rows.Count;
for (int i = 0; i <= iCount; i++)
{
GVGLCode.DeleteRow(i);
}
GVGLCode.DataBind();
I am using GridView
control in asp.net 2005 c# using .
How can I delete a particular row from GridView
.
I have written the following code. But it's not working...
DataRow dr = dtPrf_Mstr.NewRow();
dtPrf_Mstr.Rows.Add(dr);
GVGLCode.DataSource = dtPrf_Mstr;
GVGLCode.DataBind();
int iCount = GVGLCode.Rows.Count;
for (int i = 0; i <= iCount; i++)
{
GVGLCode.DeleteRow(i);
}
GVGLCode.DataBind();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您正在从 gridview 中删除该行,但随后您将再次调用 databind ,这只是将 gridview 刷新到原始数据源所在的状态。
要么从数据源中删除它,然后再进行 databind ,或者从 databind 中删除它没有重新数据绑定的gridview。
You are deleting the row from the gridview but you are then going and calling databind again which is just refreshing the gridview to the same state that the original datasource is in.
Either remove it from the datasource and then databind, or databind and remove it from the gridview without redatabinding.
您将从 gridview 中删除该行,然后将其重新绑定到数据源(仍包含该行)。 要么从数据源中删除该行,要么之后不重新绑定网格视图。
You're deleting the row from the gridview and then rebinding it to the datasource (which still contains the row). Either delete the row from the datasource, or don't rebind the gridview afterwards.
默认答案是从用作 GridView 数据源的任何集合中删除该项目。
如果该选项不理想,那么我建议您使用 GridView 的
RowDataBound
事件有选择地将行的 (e.Row
)Visible
属性设置为 false 。The default answer is to remove the item from whatever collection you're using as the GridView's DataSource.
If that option is undesirable then I recommend that you use the GridView's
RowDataBound
event to selectively set the row's (e.Row
)Visible
property to false.我的解决方案:
My solution:
从表 dtPrf_Mstr 而不是从网格视图中删除行。
Delete the row from the table dtPrf_Mstr rather than from the grid view.
你好,如何从datagridview中删除
1.通过id查询删除
2.类型
hi how to delete from datagridview
1.make query delete by id
2.type
请尝试这个代码......
Please try this code.....