如何从gridview中删除一行,这是在单击按钮时动态添加的 [英] how to delete a row from gridview which is dynamically added on button click

查看:76
本文介绍了如何从gridview中删除一行,这是在单击按钮时动态添加的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的

如何从gridview删除行
动态添加的,即单击按钮
现在我添加了更多我不想要的行

现在我要删除,如何删除该行?

请任何人可以帮助我.

谢谢你

Dear

How to can i delete a row from gridview
which is dynamically added i.e on button click
now i added more rows which i dont want

now that i want be delete, how to delete that row?

Please any one can help me.

Thank You

推荐答案

CommandName值

删除"-删除当前记录.引发RowDeleting和RowDeleted事件.



另请参见:

从网格视图中动态删除行 [ ^ ]
CommandName Value

"Delete" - Deletes the current record. Raises the RowDeleting and RowDeleted events.



SEE ALSO:

Dynamically removing rows from a grid view[^]


如果您将DataTable用作GridView的数据源,请尝试此操作..

首先在DataTable中删除一行,然后再次绑定gridView.

if you are using DataTable as DataSource for a GridView then try this..

Delete a row in DataTable First Then Bind the gridView again.

DataTable dt = (DataTable)(GridView1.DataSource);
dt.Rows.RemoveAt(GridView1.Rows.Count - 1);
dt.AcceptChanges();
GridView1.DataSource = dt;
GridView1.DataBind();



此代码将删除GirdView最后添加的新行.如果要删除任何其他索引的行,则将GridView1.Rows.Count - 1替换为索引值.

希望对您有所帮助.



this code will delete the new row added at the last of a GirdView. If you want to delete row of any other index then replace GridView1.Rows.Count - 1 with your index value.

hope it helps..


Dim RowIndex As Integer = gvRow.RowIndex
        If ViewState("CurrentTable") IsNot Nothing Then
            dt = DirectCast(ViewState("CurrentTable"), DataTable)
            If dt.Rows.Count > 1 Then
                If gvRow.RowIndex < dt.Rows.Count - 1 Then
                    'Remove the Selected Row data
                    dt.Rows.Remove(dt.Rows(RowIndex))
                End If
            End If
            'store the current data in ViewState for future reference                
            ViewState("CurrentTable") = dt
            Session("DS") = dt
            'rebind the GridView for the updated data
            dgv.DataSource = dt
            dgv.DataBind()
            For i = 0 To dgv.Rows.Count - 1
                dgv.Rows(i).Cells(0).Text = i + 1
            Next i
        End If


这篇关于如何从gridview中删除一行,这是在单击按钮时动态添加的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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