Click here to Skip to main content
15,888,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 14-Oct-11 0:32am
v2
Comments
Praveen Meghwal 14-Oct-11 7:38am    
Did you try to bind your grid after calling DeleteRow function?
SARAVANAKUMAR.M 14-Oct-11 9:11am    
After Deleting a Row from GridView , u need to call DataBind function to Bind the Gridview then only the deleted row will be removed from Gridview otherwise early binded data's will be remains in Gridview .

1 solution

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900