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. DataGrid 's Checkbox checked on Button click

DataGrid 's Checkbox checked on Button click

Scheduled Pinned Locked Moved ASP.NET
csharpjavascripthelpquestion
7 Posts 6 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
    Thats Aragon
    wrote on last edited by
    #1

    Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

    V S M I K 6 Replies Last reply
    0
    • T Thats Aragon

      Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

      V Offline
      V Offline
      varshavmane
      wrote on last edited by
      #2

      Yes use this script: function check_uncheck(Val) { var ValChecked = Val.checked; var ValId = Val.id; var frm = document.forms[0]; // Loop through all elements for (i = 0; i < frm.length; i++) { // Look for Header Template's Checkbox //As we have not other control other than checkbox we just check following statement if (this != null) { if (ValId.indexOf('CheckAll') != - 1) { // Check if main checkbox is checked, // then select or deselect datagrid checkboxes if (ValChecked) frm.elements[i].checked = true; else frm.elements[i].checked = false; } else if (ValId.indexOf('deleteRec') != - 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; } } // if } // for } // functionNow the Delete confirmation method: On button Click call this Hope this helps u??

      1 Reply Last reply
      0
      • T Thats Aragon

        Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

        S Offline
        S Offline
        Sathesh Sakthivel
        wrote on last edited by
        #3

        vhs17 wrote:

        Is there any javascript for this ? or any coding(C#)??

        Yes. There are lot of Examples are hereitself.

        SSK. Anyone who says sunshine brings happiness has never danced in the rain.

        1 Reply Last reply
        0
        • T Thats Aragon

          Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

          M Offline
          M Offline
          monu nair
          wrote on last edited by
          #4

          foreach (GridViewRow gdvRow in ResultsGrid.Rows) { CheckBox objCheckBox = (CheckBox)gdvRow.Cells[columns].Controls[1]; if (htmlCheckBox.Checked == true) { } }

          1 Reply Last reply
          0
          • T Thats Aragon

            Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

            I Offline
            I Offline
            Imran Khan Pathan
            wrote on last edited by
            #5

            HI TRY THIS SCRIPT IF YOU WANT TO CHECK ALL CHECKBOXES ON CLICK OF BUTTON for (var i = 0; i < e.form.elements.length; i++) { if (e.form.elements[i].name == "CHKNAME") //SET PROPERTY NAME="CHKNAME" FOR ALL CHECKBOXES, USE HTMLCONTROL { e.form.elements[i].checked = true; } } bEST rEGARD pATHAN

            ---------------------------------------------------

            1 Reply Last reply
            0
            • T Thats Aragon

              Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

              K Offline
              K Offline
              kapil bhatnagar
              wrote on last edited by
              #6

              pass the datagrid name via the codebehind: btnCheckAll.Attributes.Add("OnClick","javascript:return CheckAll("dgdGrid");"); function CheckAll(dataGridName) { var ChkState = true; //count the no. of rows in the DataGrid List var count = document.getElementById(dataGridName).rows.length; for(i = 2;i<=count+1; i++) { var id = dataGridName+"__ctl" + i + "_chkSelect"; var elem = document.getElementById(id); elem.checked = ChkState ; } } where "chkSelect" will be the name of the checkbox as mentioned in the item tempelate column in the html code for the datagrid. Hope this helps !!

              1 Reply Last reply
              0
              • T Thats Aragon

                Hi All, I m using one datagrid . Each record of datagrid contains checkbox. There is one button outside the Datagrid. If i click that button then all the checkbox should be checked and also confirmation msg should be display . Is there any javascript for this ? or any coding(C#)?? plz help me. Thank you Keep Smiling............:)

                T Offline
                T Offline
                Thats Aragon
                wrote on last edited by
                #7

                Thank you All..........:)

                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