如何从GridView中删除一行? [英] How to delete a row from GridView?

查看:163
本文介绍了如何从GridView中删除一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 GridView 控件 asp.net 2005 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();


解决方案

您正在从gridview中删除该行,但您然后再去调用databind,这只是刷新gridview到与原始数据源相同的状态。



将其从数据源中删除,然后将数据绑定或数据绑定并将其从gridview中删除,而无需重新绑定。


I am using GridView control in 2005 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();

解决方案

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中删除一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆