Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting a row completely from a dataset

I have a remove button on my gridview. On Clicking the remove button , the row should be completely removed from the session. I am currently doing the following :

protected void gvMainLog_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Remove")
        {

            GridViewRow rowSelect = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
            int rowindex = rowSelect.RowIndex;

            DataSet ds =  ((DataSet)Session["old"]);

            ds.Tables[0].Rows[rowindex].Delete();

            Session["old"] = ds;

            gvMainLog.DataSource = Session["old"];
            gvMainLog.DataBind();

        }

The problem is that :

ds.Tables[0].Rows[rowindex].Delete();

removes only the content in that row. When I look at the dataset , it shows an empty row.

Is there a way I can remove the entire row, without it showing an empty row ?

like image 778
CodeNinja Avatar asked Nov 28 '22 15:11

CodeNinja


1 Answers

Try calling

ds.AcceptChanges() 

after row.Delete().

like image 151
Oscar Avatar answered Dec 04 '22 23:12

Oscar