How to delete a row from GridView and set the remaining values to the
controls?
Ok,http://www.aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx">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.
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++;
}
}
}
}
Please note i am not fetching anything from database.
No comments:
Post a Comment