Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. deleting rows in gridview..

deleting rows in gridview..

Scheduled Pinned Locked Moved ASP.NET
databaseannouncement
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scar_face
    wrote on last edited by
    #1

    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

    S J 2 Replies Last reply
    0
    • S scar_face

      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

      S Offline
      S Offline
      Satish Mahapatra
      wrote on last edited by
      #2

      Have you written the deletecommand in the property like deletecommand="delete from table where rowid=2 ";

      S 1 Reply Last reply
      0
      • S Satish Mahapatra

        Have you written the deletecommand in the property like deletecommand="delete from table where rowid=2 ";

        S Offline
        S Offline
        scar_face
        wrote on last edited by
        #3

        but i want the rows to be deleted only from front end and not from database..is it possible..

        scarface

        S 1 Reply Last reply
        0
        • S scar_face

          but i want the rows to be deleted only from front end and not from database..is it possible..

          scarface

          S Offline
          S Offline
          Satish Mahapatra
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • S Satish Mahapatra

            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.

            S Offline
            S Offline
            scar_face
            wrote on last edited by
            #5

            can you just show some sample code for this..

            scarface

            1 Reply Last reply
            0
            • S scar_face

              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

              J Offline
              J Offline
              justintimberlake
              wrote on last edited by
              #6

              protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewRow myrow = (GridViewRow)chk.NamingContainer; myrow.Visible = false; } god is great

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups