且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从GridView中删除行?

更新时间:2023-12-04 11:39:22

您要删除在GridView的行但后来你会和调用数据绑定再次这是刚刚刷新GridView控件到相同的状态,原来的数据源是在

无论是从数据源中删除它​​,然后数据绑定,或和数据绑定在GridView不redatabinding删除它。

I am using asp.net 2005 c# using gridview control.

How can i delete particular row from gridview.

I wrote 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.