.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

check or uncheck boxes in datagrid using Javascript

Posted By:      Posted Date: October 14, 2010    Points: 0   Category :ASP.Net

Here is the situation: I have a checkbox in the header of the datagrid and I want to use Javascipt so when I check the box, all of the checkboxes in the datagrid are checked (or unchecked if the one on top is unchecked).  How do I reference the asp:checkboxes in the datagrid?

<script type="text/javascript" language="javascript" id="clientEventHandlersJS">
    function SelectAll(isChecked) {
        var chkb = document.getElementsByTagName('asp:checkbox')
        for (var i = 1; i < chkb.length; i++) {
            chkb[i].checked = isChecked;

<asp:DataGrid id="DataGrid2" runat="server">
        <asp:TemplateColumn SortExpression="InMailing" HeaderText="In Mailing">
            <HeaderTemplate >

View Complete Post

More Related Resource Links

Datagrid checkbox check uncheck in single click

Hi, I have a datagrid colums of checkbox type. Users have to click twice on the checkbox to check or uncheck. Is there a way to do this in one click. Thanks Vijay

Javascript code for Selection of all check boxes


        <asp:Repeater ID="rptroot" runat="server"  onitemdatabound="rptroot_ItemDataBound">
        <table style="background-color:GrayText">
        <td align="char" charoff="45%" char="." > 
        <asp:CheckBox ID="Chkroot" runat="server" Text='<%DataBinder.Eval(Container.DataItem, "ApplicationDesc")%>' />
               <b><%# DataBinder.Eval(Container.DataItem, "ApplicationDesc")%></b><br />
          <tr valign=middle ><td colspan="6">          
      <asp:Repeater ID="rptsub" runat="server">
           <td rowspan="7" >
           <asp:CheckBox ID="Chksub" runat="server" GroupName='<%DataBinder.Eval(Container.DataItem, "PermissionName")%>'/>
         <i> <%# DataBinder.Eval(Container.DataItem, "PermissionName")%></i><br />

Saving Check boxes


I am creating an application that uses several check boxes. I check one or more of these check boxes. When I save a record and reopen it all field come back with the appropriate info, except the check boxes come back unchecked. I am using a date type "bit". It apperas that I have the check boxes bound to the right fields in the table. Does anyone have any suggestions<

Keith @ LPG

Accessing a datagrid element using javascript

Hi all,as I'm not a .Net developer, I'm struggling with some simple problems using the language. I'm trying to insert some javascript functionality, inside my page. What I'm trying to do below...<script language=javascript> function ControlBackupFields(hasBackup) { if (hasBackup.checked = true) { document.aspnetForm.frequencyValue.enabled = true; document.aspnetForm.frequencyUnitList.enabled = true; } else { document.aspnetForm.frequencyValue.enabled = false; document.aspnetForm.frequencyUnitList.enabled = false; } } </script> <asp:datagrid id="dgData" runat="server" AutoGenerateColumns="False" PageSize="20" Width="100%" CssClass="grid" CellPadding="1"> <ItemStyle Height="20px" CssClass="tabletext2" VerticalAlign="Top"></ItemStyle> <HeaderStyle Height="20px" CssClass="tableheading2"></HeaderStyle> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:TextBox id="volumeID" Runat="server" Visible="false" /> <asp:Label id="volumeName" Runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:Templa

Check Page Referer in Javascript?

Is there a way to execute a javascript function based on the page referer?So if the user comes from an internal page then doesnt execute but if it comes from an external page then it does?Thanks

I am using the following code to check to see if a panel is visible or not before running javascript

Using VB, VS 2010, when I run the following code, I get an error because it executes the code even if I have Panel7 set to invisible.  I am trying to use javascript to see if the panel is visible or not before executing the code.var panelRef7 = document.getElementById('<%= Panel7.ClientID %>'); if (panelRef7) { $find('DragP7').add move(savePanelPosition); }  What am I doing wrong?   Thanks

how to check javascript is enabled

hey guys, i have a wen form that has some javascript. i want to test if a user has javascript enabled or not. if they don't i should alert them with a message so they are aware they need javascript to use the form. i had a look at this example below but this will only work is javascript is enabled! any suggestions/links? <script language="JavaScript"> <!-- function cc() { if (document.cookie == "") { alert("COOKIES need to be enabled!"); document.Form1.cookieexists.value ="false" } else { document.Form1.cookieexists.value ="true" } } document.cookie = 'killme' + escape('nothing') </script>

How to execute javascript function from datagrid row

 Hi I need to execute  a javascript function when a row of a datagrid is clicked. I am not sure how to do this. I have tried adding a template column with a button <asp:TemplateColumn>  <ItemTemplate>    <asp:Button ID="myButton" Text="Insert collection" OnClientClick="putData();" runat="server" />  </ItemTemplate></asp:TemplateColumn> And then attaching the javascript to it: myButton.Attributes.Add("onclick", "putData()") But it produces an error. Sorry this is a basic question, but what am I doing wrong?

Getting a Checkbox in a datagrid to check before RowDetails expand the row.



I am having trouble getting a checkbox in my datagrid to check in certain situations. The row details in my grid cause the row to expand when the row is selected. When no row is selected, or a row below the row just clicked was the selected row prior to the click, things work fine (the checkbox I clicked on gets toggled and the row expands to show its rowdetails). If a row above the row I am clicking was selected (and therefore expanded, showing its rowdetails) when that row collapses, my current row moves up (because the row above collapsed) and the current row expands. However, the checkbox in that row (in the column that I clicked on) does not get checked in this case. I suspect it's because it is no longer in the space where the click occurred (because it works if clicking this checkbox/row doesn't cause it to move up before expanding). Is there a way to get the checkbox click to happen before the row selection? I seem to recall properties on controls in the past that indicated whether they answered before or after their child controls (maybe that was forms) but I cannot find any such property to set on the WPF DataGrid. Any suggestions? Thanks.


How to consolidate what was actually selected with check boxes?


I have an infopath form that has 100 checkboxes returning whole numbers if checked on the form. Standard section, not in a repeating table. How can I create a summary of which boxes were checked, and the content related to the checked boxes?

I have a secondary list in sharepoint that is associated with the check boxes. Checkbox 10 =whole number 10, that references secondary ID 10. This allows me to change the secondary list, and not mess with the form.

Seems like I have tried everything to get this detail to a summary page view. I found limitations to text boxes limited to 255 characters. No luck with importing to list boxes. String statements have not produced the desired result.(probably my syntax. 

Ideally I would love to have a repeating table that grows with each checkbox and contains the secondary data, or removes the smae if unchecked. What i can gather is the repeating tables are not very robust.

Hers the kicker I would like to work within the restraints of the tools and not use code that requires admin approval each time the form updates. If i could do this within infopath or generate a summary in workflow, that would work.

I how turn to the experts.

A little help here...

Run javascript before sorting or paging the datagrid


Here is what I am trying to do;

I want it so that when the user clicks on the datagrid column headers to sort the records, or when they go to page the datagrid, that a confirmation pop-up appears first, confirming that their changes are going to be lost (unless they click "Cancel").

I have the confirmation pop-up scripted in Javascript and is added to the controls on the page using

onClientClick="return ConfirmDiscardChanges();"

How do I attach this to a datagrid header and to the pager?

Do the columns need to be Template columns and the header text being hyperlink?  If so, how do I set it up so it will, if the user clicks "OK" in the confirmation pop-up,  still sort?


Edit a DataGrid row's style by Javascript when a control is clicked.


I have a datagrid I am working with which has a few columns, but one checkbox with a javascript onclientclip event.

I want to highlight the row that the checkbox is clicked, highlighting for the user that this record has changed.

I have a CSS Class of "GrdHiglight" that can be used to override the "GrdNorm" and "GrdAlt" classes, or if I have to manually change the style for the row that is fine.

How do I reference the one row which the checkbox resides in, in the datagrid, to modify this?

Conditional Formatting - Verify a number of check boxes have been checked before showing a button?


I would like to Hide a Submit button until all the check boxes are equal to true? How would I go about verifying all boxes equal true?

Login check Using javascript for sharepoint site


Hi ,

          I am supposed to create new userid and password in sharepoint domain. There may be many login users. i need to check the login using javascript in ascx control. Can anyone tell me how to do this?

FYI ...If i have five userlogins ..then the 5 users can be able to login by this page. after the login it should be redirect to some other page too.

Thanks In Advance

Varathan GS

Group check boxes

Hi group,
How can I group a couple of check boxes on my form so that only ONE can be checked an anytime?
I've tried placing them onto a panel but I can still check them both.
Using VB.NET

DataGridViewCheckBoxColumn, Cannot Check/Uncheck at Runtime

I have a DataGridView with an Unbound CheckBoxColumn.  The remaining fields are bound programmatically when the form is loaded.

For some reason I am unable to check/uncheck the checkbox field at runtime when I click the checkbox.  I finally ended up using the CellContentClick to just do the work manually, which works fine, but I'd still like to figure this out.  The DataGridView's ReadOnly property is set to False. The CheckBoxColumn's ReadOnly property is set to false.  I attempted to set the CheckBoxColumn's ReadOnly property to false after the DataGridView was bound but this didn't seem to help either.

Does anyone have any clue as to why the default behavior for a DataGridViewCheckBoxColumn doesn't seem to be working correctly?


How to check if at least one checkbox is checked in a DataGrid



I was trying to find out if there are any check boxes checked in the datagrid, if non of them is checked it should show me an alert to select atleast one.

My problem starts when there is paging in datagrid...

not able to check the entire datagrid at a time in itemDataBound event for the checked check boxes !!!!!


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend