selvi subramanian

selvi subramanian

  • NA
  • 799
  • 572.6k

gridview row is deleted but it show again when we delete the

Jul 27 2014 4:46 AM

if i delete the  1st row in  a gridview then am going to delete  the 2nd row. if i delete the 2nd row the first row again show.but i need to delete it without affect the database.


my code is
private void BindData()
    {
        string constr = ConfigurationManager.AppSettings["s"].ToString();
        string query = "select Id, Name, Status FROM aten";

        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        DataSet ds = new DataSet();
        DataTable DataTable1 = new DataTable();
        da.Fill(DataTable1);
        GridView1.DataSource = DataTable1;
        GridView1.DataBind();
        ViewState["UsingSelectedRow"] = DataTable1;
        ViewState["UsingRowDeleting"] = DataTable1;
        ViewState["UsingLinkButtonOnClick"] = DataTable1;
        
    }
    


 protected void Delete(object sender, EventArgs e)
    {
 int index = Convert.ToInt32(((sender as LinkButton).NamingContainer as GridViewRow).RowIndex);
        DataTable dt = (DataTable)ViewState["UsingLinkButtonOnClick"];
        dt.Rows.RemoveAt(index);
        this.GridView1.DataSource = dt;
        this.GridView1.DataBind();
    }

Answers (2)