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. check box in datagrid

check box in datagrid

Scheduled Pinned Locked Moved ASP.NET
csshelpquestion
2 Posts 2 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
    suzzain
    wrote on last edited by
    #1

    Hi all, I have checkboxes in datagrid to select and a delete button outside the datagrid to delete the checked row in datagrid. After checking the check box and clicking the delete button, in the btndelete_Click im finding the check box in the datagrid and deleting the particular record, but im getting the checked false in the btndelete_Click of the datagrid checkbox which is checked. Please tell me why it is so and how can i find the checkbox of datagrid is checked or not in button click. The code is below:

    protected void btnDelete_Click(object sender, EventArgs e)
    {
    foreach (DataGridItem DemoGridItem in grid.Items)
    {
    CheckBox oCheckbox = (CheckBox)DemoGridItem.Cells[1].FindControl("chkDelete");
    HiddenField hidImageName = (HiddenField)DemoGridItem.Cells[1].FindControl("hdnItem");
    if (oCheckbox.Checked == true)
    {

                try
                {
                    Delete code;
                }
                catch( Exception e)
                {
    
                }
            }
        }
    

    }

    Thanks in advance for ur help.

    C 1 Reply Last reply
    0
    • S suzzain

      Hi all, I have checkboxes in datagrid to select and a delete button outside the datagrid to delete the checked row in datagrid. After checking the check box and clicking the delete button, in the btndelete_Click im finding the check box in the datagrid and deleting the particular record, but im getting the checked false in the btndelete_Click of the datagrid checkbox which is checked. Please tell me why it is so and how can i find the checkbox of datagrid is checked or not in button click. The code is below:

      protected void btnDelete_Click(object sender, EventArgs e)
      {
      foreach (DataGridItem DemoGridItem in grid.Items)
      {
      CheckBox oCheckbox = (CheckBox)DemoGridItem.Cells[1].FindControl("chkDelete");
      HiddenField hidImageName = (HiddenField)DemoGridItem.Cells[1].FindControl("hdnItem");
      if (oCheckbox.Checked == true)
      {

                  try
                  {
                      Delete code;
                  }
                  catch( Exception e)
                  {
      
                  }
              }
          }
      

      }

      Thanks in advance for ur help.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The real question is, where do the checkboxes come from ? Best guess, your page load is binding to the datasource and erasing any selected items.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      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