如何从gridview而不是从数据库中删除记录? [英] how to delete records from gridview but not from database?

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

问题描述

hi如何从GridView中删除记录,而不是从数据库中删除记录? 这是我的代码.

 DataTable dt =  DataTable();
        如果(grdCart.Rows.Count <  =  1 )
        {
            e.Cancel =  true ;
            Response.Write(" );
        }
        其他
        {
            如果(grdCart.SelectedIndex >  =  0 )
            {
                dt.Rows.RemoveAt(grdCart.SelectedIndex);
                e.Cancel =  false ;
                grdCart.DataSource = dt;
                grdCart.DataBind();
                grdCart.Visible =  true ;
            }
        } 

解决方案

1.您可以使用数据集和数据表来获取结果.

2,您可以在表格中有一个标志"字段,并在单击按钮时设置标志.

或,请尝试以下方式:
将数据库中的数据绑定到"dbTable"之类的数据表.使用dbTable绑定gridview.

在gridview_rowDeleting上...编写以下代码...

 dbTable.Rows [e.RowIndex] .Delete();

Gridview.DataSource = dbTable;

GridView.DataBind(); 


[DataTable dt =new DataTable(); if (grdCart.Rows.Count <=1) { e.Cancel = true; Response.Write("You Must Keep One record"); } else { if (grdCart.SelectedIndex >= 0) { dt.Rows.RemoveAt(grdCart.SelectedIndex); e.Cancel = false; grdCart.DataSource =dt; grdCart.DataBind(); grdCart.Visible = true; } }

解决方案

1. u can use a dataset and datatable to get the result.

2, u can have a "flag" field in the table and set the flag when u click the buttons.

or , try in the following way:
bind the data from database to a datatable like "dbTable". Use dbTable to bind the gridview.

on gridview_rowDeleting ...write following code...

dbTable.Rows[e.RowIndex].Delete();

Gridview.DataSource =dbTable;

GridView.DataBind();


GridView.DeleteRow Method [^] which is used to deletes the record at the specified index from the data source.
Have a look there[^]


这篇关于如何从gridview而不是从数据库中删除记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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