如何在不影响数据库的情况下从GridView中删除一行 [英] How can I delete a row from the GridView without effecting the database

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

问题描述

我在ASP.Net中有一个Webform,在此我使用了DropDownList,TextBox,我正在其中输入一些数据并使用添加"按钮,每个添加的记录都显示在gridView(未连接到数据库)中,假设它们是错误的在添加记录时的任何列中,我只想删除该特定行.因此,任何人都可以帮助我解决此问题,我必须使用哪种代码,任何人都可以为我提供代码.在此先感谢.......

我使用了下面显示的一些代码,但是有时它会删除两行(最后第二行和最后一行),有时只删除一行...



I have a Webform in ASP.Net, In this I used DropDownList,TextBox I am Entering some data into this and Using Add Button, Every Added records display in gridView(Not Connected to DataBase), Suppose if their is some mistake in any column while Adding records I want to delete that particular rows only. So could any body will help me to sort out of this problem, what kind of code i have to used, can anybody provide me the code. Thanks in Advance.......

I have used Some code shown below But Sometimes it delete two rows (2nd last and last rows) and some times only one rows...



DataTable dt = (DataTable)Session["additems"];
       if (dt.Rows.Count > 0)
       {
           dt.Rows.RemoveAt(e.RowIndex);
       }
       Session["additems"] = dt;
       bindGrid();

推荐答案

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     dt = (DataTable)ViewState["dt"];
     dt.Rows[e.RowIndex].Delete();
     GridView1.DataSource = dt;
     GridView1.DataBind();
 }


这篇关于如何在不影响数据库的情况下从GridView中删除一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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