Click here to Skip to main content
15,917,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok,CLICK ME[^] ! THis is what i have right now... but i want to add a delete functionality. I have added a delete command button column and on its click event i am deleting the particular row. But my problem is that i am unable to retain the remaining row's values in the controls.


C#
protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        DataTable dtCurrentTable=new DataTable();
        int RowIndex = e.RowIndex;
        dtCurrentTable = (DataTable)ViewState["CurrentTable"];
        dtCurrentTable.Rows.RemoveAt(e.RowIndex);

        SetPreviousData1(dtCurrentTable);

    }

private void SetPreviousData1(DataTable dtCurrentTable)
    {
        int rowIndex = 0;
        if (dtCurrentTable != null)
        {
            DataTable dt = dtCurrentTable;
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
                    TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
                    TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");

                    box1.Text = dt.Rows[i]["Column1"].ToString();
                    box2.Text = dt.Rows[i]["Column2"].ToString();
                    box3.Text = dt.Rows[i]["Column3"].ToString();

                    rowIndex++;
                }
            }
        }
    }
Posted
Comments
Richard C Bishop 17-Sep-13 13:08pm    
Are you rebinding the Gridview after the delete statement?
arbaaz jalil 17-Sep-13 13:40pm    
I am not fetching any data from database . But i want to retain the remaining rows alongwith its values that i had entered after i delete a row.
Richard C Bishop 17-Sep-13 15:09pm    
That does not matter, if you do not rebind the gridview it will appear as if nothing happened.

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