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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to delete selected item from datagrid

how to delete selected item from datagrid

Scheduled Pinned Locked Moved ASP.NET
helptutorial
6 Posts 5 Posters 1 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
    sooreeagt
    wrote on last edited by
    #1

    Hai all... i want code for delete a selected row from datagrid. i have checkboxes on every row if i check and press delete button .That should be deleted. any one have code or any idea plz help me

    Suresh.R

    N M 2 Replies Last reply
    0
    • S sooreeagt

      Hai all... i want code for delete a selected row from datagrid. i have checkboxes on every row if i check and press delete button .That should be deleted. any one have code or any idea plz help me

      Suresh.R

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      sooreeagt wrote:

      want code for delete a selected row from datagrid

      Start a loop till datagrid item count. Find the checkbox using findcontrol method. Check it is checked. If checked then delete. Code could be something like

      private void DeleteGrid()
      {
          for(int i=0;i<=DataGridName.Items.Count-1;i++){
             CheckBox chk = (CheckBox)DataGridName.Items[i].FindControl("yourcontrolName");
             if ( chk.Checked )
                //Do delete
          }
      }

      Y 1 Reply Last reply
      0
      • N N a v a n e e t h

        sooreeagt wrote:

        want code for delete a selected row from datagrid

        Start a loop till datagrid item count. Find the checkbox using findcontrol method. Check it is checked. If checked then delete. Code could be something like

        private void DeleteGrid()
        {
            for(int i=0;i<=DataGridName.Items.Count-1;i++){
               CheckBox chk = (CheckBox)DataGridName.Items[i].FindControl("yourcontrolName");
               if ( chk.Checked )
                  //Do delete
            }
        }

        Y Offline
        Y Offline
        yuvachandra
        wrote on last edited by
        #3

        Do this ////in the delete button click CheckBox cb; foreach(DataGridItem it in DataGrid1.Items) { cb=(CheckBox)it.FindControl("CheckBox1"); if(cb.Checked==true) { string st=((Label)it.Cells[1].FindControl("Primary keycolumn name")).Text; dataAdapter =new SqlDataAdapter("delete from AccountCode where AccountId=" + st,con); dataAdapter.Fill(ds,"deleteTable"); } } DisplayRecords(); //some procedure to bind the data This should run...make modifications curructly:rose::rose:

        Y 1 Reply Last reply
        0
        • Y yuvachandra

          Do this ////in the delete button click CheckBox cb; foreach(DataGridItem it in DataGrid1.Items) { cb=(CheckBox)it.FindControl("CheckBox1"); if(cb.Checked==true) { string st=((Label)it.Cells[1].FindControl("Primary keycolumn name")).Text; dataAdapter =new SqlDataAdapter("delete from AccountCode where AccountId=" + st,con); dataAdapter.Fill(ds,"deleteTable"); } } DisplayRecords(); //some procedure to bind the data This should run...make modifications curructly:rose::rose:

          Y Offline
          Y Offline
          yuvachandra
          wrote on last edited by
          #4

          Or you can go through this one [http://www.dotnetjohn.com/articles.aspx?articleid=51](<a href=)[^]" rel="nofollow"> Do it:rose:...yuva

          S 1 Reply Last reply
          0
          • Y yuvachandra

            Or you can go through this one [http://www.dotnetjohn.com/articles.aspx?articleid=51](<a href=)[^]" rel="nofollow"> Do it:rose:...yuva

            S Offline
            S Offline
            Sherin Iranimose
            wrote on last edited by
            #5

            Hi, Hi please reply to the original message. Then only the person grta notification mail.


            To succeed, we must first believe that we can. Sherin Iranimose


            1 Reply Last reply
            0
            • S sooreeagt

              Hai all... i want code for delete a selected row from datagrid. i have checkboxes on every row if i check and press delete button .That should be deleted. any one have code or any idea plz help me

              Suresh.R

              M Offline
              M Offline
              metallica_rock10
              wrote on last edited by
              #6

              In the properties of your datagrid there will be something called datakeyfield set it to the primary key of your table and the write a function which calls normal delete in DB. For this press on the lightning icon i the properties and select deletecommand type the function in it and press enter then wirte your code in that block.

              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