如何在没有数据库连接的情况下在网格视图中删除(空/空白)行 [英] How to delete a (empty/blank)row in a grid view without database connection

查看:81
本文介绍了如何在没有数据库连接的情况下在网格视图中删除(空/空白)行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在过去的几个月中,我一直试图删除在网格视图中为空的行.我在我的应用程序中使用网格视图,如果用户错误地添加了一行,我将无法在网格视图中删除行.在这里我想删除没有数据库连接的行.我已经尝试过下面的代码,但无法正常工作.请帮助我..,

受保护的void GridView1_RowDeleting(对象发送者,GridViewDeleteEventArgs e)
{
int categoryID =(int)GridView1.DataKeys [e.RowIndex] .Value;
GridView1.DeleteRow(categoryID);
}

在此先谢谢
Lohith

Hi,
From the past few months i have been trying to delete a row which is empty in a grid view. I am using grid view in my application where, if in case user adds a row by mistake n i''m not able to delete a row in grid view. Here i want to delete a row with no database connection. I have tried this below code but its not working. Please help me out of this..,

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int categoryID = (int)GridView1.DataKeys[e.RowIndex].Value;
GridView1.DeleteRow(categoryID);
}

Thanks In advance
Lohith

推荐答案

我的理解是您有一个绑定到数据库的datagridview并且用户输入新行,而问题是如果用户输入了错误的数据,您应该能够在数据网格视图中突出显示该行并通过单击按钮将其删除?

如果是这样,您可以执行以下操作-"dg"是我的datagridview的名称

My understanding is that you have a datagridview bound to a database and user enters new rows and your problem is if the user enters a wrong data, you should be able to highlight the row in the datagrid view and delete it by a click of a button ?

If that is the case, you can do the following - "dg" is the name of my datagridview

private void button1_Click(object sender, EventArgs e)
      {
          try
          {
              dg.Rows.Remove(dg.CurrentRow);
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }


这篇关于如何在没有数据库连接的情况下在网格视图中删除(空/空白)行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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