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. aspxgridview and checkbox problem

aspxgridview and checkbox problem

Scheduled Pinned Locked Moved ASP.NET
javajavascripttoolshelp
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.
  • T Offline
    T Offline
    tomorrow_ft
    wrote on last edited by
    #1

    Quote:

    hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem., <script language="javascript" type="text/javascript"> function SelectAll(id) { var IsChecked = id.checked; var Chk = id; // Parent = document.getElementById('GrdPerliste'); Parent = document.getElementById('<% = GrdPerliste.ClientID%>'); var items = Parent.getElementsByTagName('input'); for (i = 0; i < items.length; i++) { var deneme = items[i].type; if (items[i].id != Chk && items[i].type == "checkbox") { if (items[i].checked != IsChecked) { items[i].click(); } } } } </script> protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }

    S 1 Reply Last reply
    0
    • T tomorrow_ft

      Quote:

      hi, I am using an aspxgridview and two checkboxes(for header and dataitem).When I check header checkbox I want to check all checkbox.I am also using java script code.essentially, I can do this, but I must check header checkbox twice times.I didnt understand why it is happening.ı am writing this code checkbox_checked event and header checkbox's autopostpak is true. When I used normal gridview I didnt have any problem I could do this without problem., <script language="javascript" type="text/javascript"> function SelectAll(id) { var IsChecked = id.checked; var Chk = id; // Parent = document.getElementById('GrdPerliste'); Parent = document.getElementById('<% = GrdPerliste.ClientID%>'); var items = Parent.getElementsByTagName('input'); for (i = 0; i < items.length; i++) { var deneme = items[i].type; if (items[i].id != Chk && items[i].type == "checkbox") { if (items[i].checked != IsChecked) { items[i].click(); } } } } </script> protected void Checksec_CheckedChanged2(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; GridViewHeaderTemplateContainer bulundugucontainer = (GridViewHeaderTemplateContainer)chk.NamingContainer; ((CheckBox)bulundugucontainer.FindControl("Checksec")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)bulundugucontainer.FindControl("Checksec")).ClientID + "')"); }

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      First, your issue/flow of why two clicks This happens as you add the onclick attribute in checkchanged event. So, for a fresh page, first click postbacks and you register javaScript code for checkbox. Second click uses this registered JS method and you get what you want. You can do it without any postback or server event - just using a Javascript. You need to attach the JS code to checkbox in Grid's RowDataBound event where very rowbind is called. Once this is done, single click would work. Have a look at these: Using JavaScript with ASP.Net GridView Control[^] Using jQuery without RowDataBound code[^]

      Sandeep Mewara [My last tip/trick]: Server side Delimiters in ASP.NET[^]

      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