Deleting a row in datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • looserash
    New Member
    • Mar 2008
    • 8

    Deleting a row in datagrid

    hi,

    Can anyone please help me solve the problem m facing with the datagrid.
    I want to delete a row in the datagrid and correspondingly i want that data to be deleted in database .

    thanks,
  • indianmaestro
    New Member
    • Mar 2008
    • 16

    #2
    in the datagrid add one more column with links for each row
    for the link (onclick event) write the code to delete the row based on the id of that perticular row from the database table

    at the end redirect the page to the same page so the item deleted will not be shown in the grid, or else u have to refresh the page to see the effect.

    Comment

    • looserash
      New Member
      • Mar 2008
      • 8

      #3
      hi,

      i have added that delete button column and i have written the code ..its not working and after deleting i have binded the datagrid so hlep me with this.
      thank u.

      Comment

      • Rajalakshmimca08
        New Member
        • Sep 2008
        • 2

        #4
        How to delete a row from datagrid?

        button1_click()
        {
        int i=dataGridView1 .CurrentRow.Ind ex;
        dataGridView1.R ows.RemoveAt(i) ;
        }

        another methos is:

        int i=dataGridView1 .CurrentRow.Ind ex;
        DataTable dt = dataGridView1.D ataSource as DataTable;
        DataRow rw=dt.Rows[i];
        rw.Delete();

        Comment

        • Rajalakshmimca08
          New Member
          • Sep 2008
          • 2

          #5
          how to delete a row in the datagrid and correspondingly that data to be deleted in database ?


          private void delete_Click(ob ject sender, EventArgs e)
          {
          string ss = dataGridView1.C urrentRow.Cells[0].Value.ToString ();
          con.Open();
          string s = "delete from stutbl where regno='" + ss + "'";
          SqlCommand cmd = new SqlCommand(s, con);
          cmd.ExecuteNonQ uery();
          }

          Comment

          Working...