deleting rows in gridview..
-
after selecting the rows through checkbox in first gridview and transfering them to second gridview i want the selected rows to get deleted from the first gridview..i want to delete the rows only in the front end and not from database since i have used sql data source to fill the first gridview..is this possible..below is the code which i have used..
foreach (GridViewRow row in GridView1.Rows)
{
string upstr = "UPDATE emp SET flag = '1' WHERE empId = ";
CheckBox ch = (CheckBox)(row.FindControl("chkbx1"));if (ch.Checked == true) { int Id = Convert.ToInt32(GridView1.DataKeys\[row.RowIndex\].Value); idArr.Add(Id); upstr += "'" + Id + "'"; conn = new SqlConnection(constr); conn.Open(); SqlCommand comm = new SqlCommand(upstr, conn); comm.ExecuteNonQuery(); conn.Close(); GridView1.DeleteRow(Id); //row.Visible = false; ch.Checked = false; } }
when i am compiling this am getting ""Deleting is not supported by data source 'empReq' unless DeleteCommand is specified."
scarface
-
after selecting the rows through checkbox in first gridview and transfering them to second gridview i want the selected rows to get deleted from the first gridview..i want to delete the rows only in the front end and not from database since i have used sql data source to fill the first gridview..is this possible..below is the code which i have used..
foreach (GridViewRow row in GridView1.Rows)
{
string upstr = "UPDATE emp SET flag = '1' WHERE empId = ";
CheckBox ch = (CheckBox)(row.FindControl("chkbx1"));if (ch.Checked == true) { int Id = Convert.ToInt32(GridView1.DataKeys\[row.RowIndex\].Value); idArr.Add(Id); upstr += "'" + Id + "'"; conn = new SqlConnection(constr); conn.Open(); SqlCommand comm = new SqlCommand(upstr, conn); comm.ExecuteNonQuery(); conn.Close(); GridView1.DeleteRow(Id); //row.Visible = false; ch.Checked = false; } }
when i am compiling this am getting ""Deleting is not supported by data source 'empReq' unless DeleteCommand is specified."
scarface
Have you written the deletecommand in the property like deletecommand="delete from table where rowid=2 ";
-
Have you written the deletecommand in the property like deletecommand="delete from table where rowid=2 ";
-
but i want the rows to be deleted only from front end and not from database..is it possible..
scarface
Then i think put the data in an xml format or any dataset.whichever rows you select for delete, delete them from the dataset.Then bind it to Grid.
-
Then i think put the data in an xml format or any dataset.whichever rows you select for delete, delete them from the dataset.Then bind it to Grid.
-
after selecting the rows through checkbox in first gridview and transfering them to second gridview i want the selected rows to get deleted from the first gridview..i want to delete the rows only in the front end and not from database since i have used sql data source to fill the first gridview..is this possible..below is the code which i have used..
foreach (GridViewRow row in GridView1.Rows)
{
string upstr = "UPDATE emp SET flag = '1' WHERE empId = ";
CheckBox ch = (CheckBox)(row.FindControl("chkbx1"));if (ch.Checked == true) { int Id = Convert.ToInt32(GridView1.DataKeys\[row.RowIndex\].Value); idArr.Add(Id); upstr += "'" + Id + "'"; conn = new SqlConnection(constr); conn.Open(); SqlCommand comm = new SqlCommand(upstr, conn); comm.ExecuteNonQuery(); conn.Close(); GridView1.DeleteRow(Id); //row.Visible = false; ch.Checked = false; } }
when i am compiling this am getting ""Deleting is not supported by data source 'empReq' unless DeleteCommand is specified."
scarface
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewRow myrow = (GridViewRow)chk.NamingContainer; myrow.Visible = false; } god is great