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. Checkbox in a grid

Checkbox in a grid

Scheduled Pinned Locked Moved ASP.NET
javascriptcss
10 Posts 5 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
    SreejithAchutan
    wrote on last edited by
    #1

    If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent

    M N S R 4 Replies Last reply
    0
    • S SreejithAchutan

      If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      http://www.google.com/search?source=ig&hl=en&rlz=&q=Datagrid+with+checkbox&btnG=Google+Search[^]

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      1 Reply Last reply
      0
      • S SreejithAchutan

        If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent

        N Offline
        N Offline
        neerubee
        wrote on last edited by
        #3

        Check this link http://www.c-sharpcorner.com/UploadFile/sd_patel/DataGridAndCheckBoxes11232005060439AM/DataGridAndCheckBoxes.aspx[^]

        Thanks & Regards Niranjan

        1 Reply Last reply
        0
        • S SreejithAchutan

          If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent

          S Offline
          S Offline
          Sun Rays
          wrote on last edited by
          #4

          Hey, try this.. Javascript function var chkT; function Test(chkT) { alert(chkT.checked); } Add template filed. In that add checkbox and then find control in RowDataBound event of Gridview. Code behind file. try { CheckBox chk = (CheckBox)e.Row.Cells[6].FindControl("chkTest"); chk.Attributes.Add("onclick", "javascript:Test(this);"); } catch(Exception ex) { } See whats happening...

          Thanks, Sun Rays To get something you must have to try once. My Articles

          S 1 Reply Last reply
          0
          • S Sun Rays

            Hey, try this.. Javascript function var chkT; function Test(chkT) { alert(chkT.checked); } Add template filed. In that add checkbox and then find control in RowDataBound event of Gridview. Code behind file. try { CheckBox chk = (CheckBox)e.Row.Cells[6].FindControl("chkTest"); chk.Attributes.Add("onclick", "javascript:Test(this);"); } catch(Exception ex) { } See whats happening...

            Thanks, Sun Rays To get something you must have to try once. My Articles

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

            Thanks for ur kind reply. I tried like that and i got the click event ,but the pbm is when i uncheck the checkbox i want to call another javascript function.

            S 1 Reply Last reply
            0
            • S SreejithAchutan

              Thanks for ur kind reply. I tried like that and i got the click event ,but the pbm is when i uncheck the checkbox i want to call another javascript function.

              S Offline
              S Offline
              Sun Rays
              wrote on last edited by
              #6

              Hi, when you will uncheck you will get item.checked = false. so you can write if condition. if(item.checked == true) { //call here Checked function } else { //call here Unchecked function } Hope it will help you

              Thanks, Sun Rays To get something you must have to try once. My Articles

              S 1 Reply Last reply
              0
              • S SreejithAchutan

                If we have a checkbox in a grid when we check the the checkbox a javascript function will be called and if we uncheck the same checkbox another javascript will be called.How is it possible...Its Urgent

                R Offline
                R Offline
                rahul net11
                wrote on last edited by
                #7

                Hi This could help. function select_deselectAll (chkVal, idVal) { var frm = document.forms[0]; // Loop through all elements for (i=0;i< frm.length; i++) { // Look for our Header Template's Checkbox if (idVal.indexOf ('CheckAll') != -1) { // Check if main checkbox is checked, then select or deselect datagrid checkboxes if(chkVal == true) { frm.elements[i].checked = true; } else { frm.elements[i].checked = false; } // Work here with the Item Template's multiple checkboxes } else if (idVal.indexOf ('DeleteThis') != -1) { // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox if (frm.elements[i].checked == false) { frm.elements[1].checked = false; //Uncheck main select all checkbox } } } } function confirmDelete (frm) { // loop through all elements for (i=0; i { // Look for our checkboxes only if (frm.elements[i].name.indexOf("DeleteThis") !=-1) { // If any are checked then confirm alert, otherwise nothing happens if(frm.elements[i].checked) { return confirm ('Are you sure you want to delete your selection(s)?') } } } } CellPadding="3" CellSpacing="0" Font-Size="9pt" AutoGenerateColumns="False" HeaderStyle-BackColor="darkred" HeaderStyle-ForeColor="white"> < Columns> < asp:TemplateColumn> < HeaderTemplate> < asp:CheckBox ID="CheckAll" OnCheckedChanged="javascript: return select_deselectAll (this.checked,this.id);" runat="server" /> < font face="Webdings" color="white" size="4">< /font> < /HeaderTemplate> < ItemTemplate> < asp:CheckBox ID="DeleteThis" OnCheckedChanged="javascript: return select_deselectAll (this.checked, this.id);" runat="server" /> < /ItemTemplate> < /asp:TemplateColumn> < asp:TemplateColumn> < HeaderTemplate> ID < /HeaderTemplate> < ItemTemplate> < asp:Label ID="StoreID" Text='< %# DataBinder.Eval (Container.DataItem, "ID") %>' runat="server"/> < /ItemTemplate> < /asp:TemplateColumn> < asp:BoundColumn HeaderText="Store" Datafield="Store" runat="server" /> < asp:BoundColumn HeaderText="Address" Datafield="Address" runat="server" /> < asp:BoundColumn HeaderText="City" Datafield="City" runat="server" /> <

                1 Reply Last reply
                0
                • S Sun Rays

                  Hi, when you will uncheck you will get item.checked = false. so you can write if condition. if(item.checked == true) { //call here Checked function } else { //call here Unchecked function } Hope it will help you

                  Thanks, Sun Rays To get something you must have to try once. My Articles

                  S Offline
                  S Offline
                  SreejithAchutan
                  wrote on last edited by
                  #8

                  CheckBox ch = (CheckBox)e.Row.Cells[1].FindControl("ChkEdit"); if (ch.Checked == true) { ch.Attributes.Add("onclick", "javascript:Del(this);"); } else ch.Attributes.Add("onclick", "javascript:BtnAdd_onClick(this);"); I given like that but i wont work

                  S 1 Reply Last reply
                  0
                  • S SreejithAchutan

                    CheckBox ch = (CheckBox)e.Row.Cells[1].FindControl("ChkEdit"); if (ch.Checked == true) { ch.Attributes.Add("onclick", "javascript:Del(this);"); } else ch.Attributes.Add("onclick", "javascript:BtnAdd_onClick(this);"); I given like that but i wont work

                    S Offline
                    S Offline
                    Sun Rays
                    wrote on last edited by
                    #9

                    Hey, u have mistaken.. Not here.. In Javascript write function... Call only a single function from codebehind... But make difference in Javascript... Got it ? :)

                    Thanks, Sun Rays To get something you must have to try once. My Articles

                    S 1 Reply Last reply
                    0
                    • S Sun Rays

                      Hey, u have mistaken.. Not here.. In Javascript write function... Call only a single function from codebehind... But make difference in Javascript... Got it ? :)

                      Thanks, Sun Rays To get something you must have to try once. My Articles

                      S Offline
                      S Offline
                      SreejithAchutan
                      wrote on last edited by
                      #10

                      Is it possible to call 2 javascript function on a checkbox in a grid on onclick event.one is onclick="return Select(this);" .if possible to call another javascript function on the same onclick event..

                      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