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

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

gridview check box validation using js

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net


i'm using a gridview with checkboxes.i want to validate if checkbox is checked or not on button click event.based on that i've to display a message.for that i used th following function.but it's not working.

function check() {
            var grid = document.getElementById("<%grdOrgRes.ClientID %>");
            if (grid.rows.length > 0) {
                for (i = 1; i < grid.rows.length; i++) {
                    cell = grid.rows[i].cells[0];
                    for (j = 0; j < cell.childNodes.length; j++) {
                        if (cell.childNodes[j].type == "checkbox") {
                            if (cell.childNodes[j].checked==false) {

View Complete Post

More Related Resource Links

Check All with JQuery and a Asp.Net GridView

Display a Grid on the screen with a checkbox in each row. At the bottom of the page have "Check All" button.

Typically if I need to do anything interesting I use a template column. So my GridView will look like the one below (most other columns removed for readability). The only interesting point to note is the CssClass="ApprovalCheckBox" in the CheckBox ItemTemplate.

Disable check box in a gridview does not working



I have a check box in a template field in a gridview.

Based on some condition, I want those check boxs to  be enable and disable.

I am trying the below code but does working..

 protected void GVstudents_RowDataBound(object sender, GridViewRowEventArgs e)
              if (e.Row.RowType == DataControlRowType.DataRow)
                    string studentID = GVstudents.DataKeys[0].Value.ToString();
                    int stdID = Convert.ToInt32(studentID);
                    int schID = profile.getSchoolIDByStudentID(stdID);
                    int tchrID = profile.getTeacherIDByStudentID(stdID);

                    if (patti.chkIsTeacherPaid(stdID, schID, tchrID))
                        CheckBox cb = (CheckBox)e.Row.FindControl("chkTeacherPayment");
                        cb.Enabled = false;
                        cb.Checked = true;


any help??

Gridview check all not working in Mozila Firefox


hi all,

i has an gridview first column header is Checkbox, when i click on that all the detail column checkboxes were selected if i use IE but the same not working in Mozila Firefox

below is my code

function checkAll()
                  var totalChkBoxes = parseInt('<%= gv5.Rows.Count %>');
                  var gvControl = document.getElementById('<%= gv5.ClientID %>');
                  var gvChkBoxControl = "cbCheckProd";
                  var mainChkBox = document.getElementById("chkBoxAll");
                  var inputTypes = gvControl.getElementsByTagName("input");
                  for (var i = 0; i < inputTypes.length; i++)

how to apply validation controls on Gridview which is created dynamically

 hi, i created a gridview with two columns and 8 rows dynamically. All the rows are empty and editable at runtime. I am giving column names for this grid from some other .aspx page by passing column names using querystring.Because i am using this grid for three different pairs of column names.  i would like to know how to apply Required Field Validator, Regular Expression Validator  and Range Validator on Gridview textboxes. So that by using those validators i want to validate user inputs. And i would also like to know how to add rows at runtime for this grid. I am using ASP.net 2.0 and C#.net for this.(Visual Studio 2005) The code i am using to create gridview is below. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="LoadData.aspx.cs" Inherits="LoadData" %>  <form id="form1" runat="server">  <div> <asp:GridView ID="GrdDynamic" runat="server" AutoGenerateColumns="False" ForeColor="#333333" BorderColor="GradientInactiveCaption" BorderStyle="Solid" style="z-index: 108; left: 24px; position: absolute; top: 13px">  <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  <RowStyle BackColor="#EFF3FB"

GridView EditItem FileUpload validation

Hey allI am using a gridview that contains an asp:fileupload so that when the user clicks 'edit' they can upload a pdf. I need to validate the size of the file, it needs to be less then a certain size. I tried to use a custom validator, but it never get called when the user updates. Is there a way to do this? How can I validate the file size on edit in the gridview?Thank youAaron

How to make cause validation false for Show Edit buttons in Gridview control

  HI. I am having 2 (dept name, City)dropdownlist, 1 Save button once if we click the save then record will be displayed in grid (Gridview with ShowEditbutton =true and I have Edit logic in my page). But if I click on Edit button then if I try to update the value then it is firing a message "Select dept" because dept dropdown present in the page so I want to make cause validation false for Show Edit buttons (update and cancel). Pleaase tell me Thanks

How to check a radiobutton just by clicking the gridview row


Hi guys.

I've a gridview with 3 columns. 2 are boundfiels and 1 itemTemplate (radiobutton)

<asp:GridView ID="GridViewMoveType" runat="server" CellPadding="4" AllowPaging="True" PagerStyle-BackColor="White" PageSize="15" Width="100%" HeaderStyle-BackColor="White" HorizontalAlign="Left" CssClass="rowodd" AutoGenerateColumns="False" GridLines="None" DataKeyNames="MoveTypeID">
                    <AlternatingRowStyle HorizontalAlign="Left" CssClass="roweven" VerticalAlign="Top" />
                         <asp:BoundField DataField="MoveTypeID" HeaderStyle-Width="5%" ItemStyle-HorizontalAlign="Right" ControlStyle-CssClass="itemAlign" InsertVisible="False" Visible="true" />
                         <asp:BoundField DataField="MoveTypeLongDescr" HeaderStyle-Width="95%" HeaderStyle-HorizontalAlign="Right" ItemStyle-HorizontalAlign="Right" SortExpression="InputLongDescr" />

Gridview Check box and Parse()



Documentation for using a checkbox with a gridview has the following statement:


Because a check box can display only a selected or an unselected state, a CheckBoxField object can be bound only to a field with a Boolean data type or a string that can be parsed by Parse.


No example has yet been found to explain how using Parse to control the value of theis done.  Interestingly enough I can find a fine example for the unlikely scenario of embedding a bulleted list in a grid cell. 

How can get a Y/N (or Y/blank) value into the checkbox field?

Gridview Sum validation


Hi All,

Seem to have a problem validating values in a gridview - This is the scenario

I have a webform that allows the user adds values to a cheque amount field and 3 subaccounts fields - the 3 subaccounts have validators in place so they will always total up to what the Cheque amount.

Problem is After the data is added and validated it goes onto a gridview that lets users edit the data - This is where they are able to bypass validating the amounts.

 Is there a way to validate sums in a gridview ?


GridView Selected rows validation


Hi All,


I want some solution for my gridview to validated only selected rows.


What is the senario:


In my gridview there are 1 templatecolumn - Total Balance -txtTotalBalance


1 another templatecolumn - Amount Received -txtAmountReceived


There are checkboxes

I want to compare only that row which is checked with txtTotalBalance with txtAmountReceived  should not be greater than totalbalance.


In current code all rows validating compare validator.That I don't want.


Please give me solution-If possible then please send me the code also..

Thanks in advance

Swapnil Malviya

How to check CheckBox.IsChecked property if CheckBox is in header of ListView/GridView with grouping


Sorry for this difficult title :P

So what exactly I need? I will try to explain it step by step as easy as possible.
My question is on the end of this post, but to understand my issue is better to read all steps.

First have a look on this post http://msdn.microsoft.com/en-us/library/ms754027(v=VS.90).aspx

1) I am implementing allmost the same code. 
But I changed one TextBlock (in Expander.Header) for a CheckBox:

<ListView x:Name="ExampleListView"
 ItemsSource="{Binding Source={StaticResource Src}}"

 <GridViewColumn DisplayMemberBinding="{Binding Path=PropertyOne}" Header="One" />
 <GridViewColumn DisplayMemberBinding="{Binding Path=PropertyTwo}" Header="Two" />


Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Using a CompareValidator to check input is a valid date

The CompareValidator can do more than just compare two controls. You can also compare it against several of the main .net data types such as Date, Integer, Double and Currency.

To do this you would set Operator="DataTypeCheck" and instead of setting the ControlToCompare or ValueToCompare attributes as you normally would you use the Type="Date" (or any of the data types I have listed above).

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net
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