how to check all the row level checkbox when header level checkbox is checked

hello 

i m working on one site which requires the functionality like yahoo, that is when we check header level check box then all row level checkbox is checked.

i m sending my code here....

<script language="javascript" type="text/javascript">
        function Check(chk)
        {
          alert("abc");
            if(document.form1.HeaderLevelCheckBox.checked==true)
            {
            alert("hello");
            for (i = 0; i < chk.length; i++)
                chk[i].checked = true ;
            }
            else
            {
            for (i = 0; i < chk.length; i++)
            chk[i].checked = false ;
            }
         }
     </script>

body part...................................

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="sno"
                DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display."
                Style="z-index: 102; left: 147px; position: absolute; top: 76px">
                <Columns>
                <asp:TemplateField>
                <HeaderTemplate>
                     <asp:CheckBox runat="server" ID="HeaderLevelCheckBox" onClick="SelectAll()"/>
                </HeaderTemplate>
             <ItemTemplate>
                <asp:CheckBox runat="server" ID="RowLevelCheckBox"/>
              </ItemTemplate>
            </asp:TemplateField>
                    <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                    <asp:BoundField DataField="per" HeaderText="per" SortExpression="per" />
                    <asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
                   
                     <asp:TemplateField>
                <ItemTemplate>
                    <a href='Ragistratoin.aspx?id=<%# Eval("sno")%>'>Edit</a>
                </ItemTemplate>
            </asp:TemplateField>
           
                    
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString1 %>"
                DeleteCommand="DELETE FROM [Table1] WHERE [sno] = @sno" InsertCommand="INSERT INTO [Table1] ([name], [per], [status]) VALUES (@name, @per, @status)"
                ProviderName="<%$ ConnectionStrings:DatabaseConnectionString1.ProviderName %>"
                SelectCommand="SELECT [sno], [name], [per], [status] FROM [Table1]" UpdateCommand="UPDATE [Table1] SET [name] = @name, [per] = @per, [status] = @status WHERE [sno] = @sno">
                <InsertParameters>
                    <asp:Parameter Name="name" Type="String" />
                    <asp:Parameter Name="per" Type="Double" />
                    <asp:Parameter Name="status" Type="String" />
                </InsertParameters>
                <UpdateParameters>
                    <asp:Parameter Name="name" Type="String" />
                    <asp:Parameter Name="per" Type="Double" />
                    <asp:Parameter Name="status" Type="String" />
                    <asp:Parameter Name="sno" Type="Int32" />
                </UpdateParameters>
                <DeleteParameters>
                    <asp:Parameter Name="sno" Type="Int32" />
                </DeleteParameters>
            </asp:SqlDataSource>


 

0
rajesh_it1
1/24/2009 6:51:39 AM
asp.net.client-side 24353 articles. 1 followers. Follow

1 Replies
847 Views

Similar Articles

[PageSpeed] 50

Hi

try this example:

<script type="text/javascript">

    function SelectAll(id) {

        var frm = document.forms[0];

        for (i=0;i<frm.elements.length;i++) {

            if (frm.elements[i].type == "checkbox") {

                frm.elements[i].checked = document.getElementById(id).checked;

            }

        }

    } 

</script>

<!-- assuming that SqlDataSource1 is the datasource for my GridView -->

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" Width="400px">

    <Columns>

        <asp:TemplateField>

            <AlternatingItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </AlternatingItemTemplate>

            <ItemTemplate>

                <asp:CheckBox ID="CheckBox1" runat="server" />

            </ItemTemplate>

            <HeaderTemplate>

                <asp:CheckBox ID="cbSelectAll" runat="server" Text="Select All" />

            </HeaderTemplate>

            <HeaderStyle HorizontalAlign="Left" />

            <ItemStyle HorizontalAlign="Left" />

        </asp:TemplateField>

    </Columns>

</asp:GridView>

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
 {

    if (e.Row.RowType == DataControlRowType.Header)
 {

        //adding an attribute for onclick event on the check box in the header

        //and passing the ClientID of the Select All checkbox

        ((CheckBox)e.Row.FindControl("cbSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("cbSelectAll")).ClientID + "')");

    }

}

and to get checked row for delete with Delete button

foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox checkbox = (CheckBox)row.FindControl("cbxId");

            if (checkbox.Checked == true)
            {
                int Id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
               // your delete method here

            }

        }
       

Good Luck

here is a site i used for that:

http://www.davidhayden.com/blog/dave/archive/2007/11/18/CheckAllCheckBoxesGridViewUsingClientSideJavascript.aspx

Very good resource

0
yasserzaid
1/24/2009 3:36:25 PM
Reply:

Similar Artilces:

checking checkbox is checked or not using checkbox.checked
Hi,my checkbox is<asp:CheckBox ID="Chkcity" runat="server" Text="My own city"  OnCheckedChanged="EventHandler"/>code behind: Private Sub Chkcity_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Chkcity.CheckedChangedif (Chkcity ...............)end if End SubERROR    'EventHandler' is not a member of 'ASP.bpoaddjob_aspx'.    Please Mark the post as "ANSWER" if it helps you I think it should be like this:<asp:CheckBox ID="Chkcity"...

Check All Check Box While Check Header CheckBox
 hello...I have two grid on same page...both grid contains header checkbox and item checkbox i want that if use check header checkbox then all item check box checked,i have javascript for this functinality but problem is that when i click on header check box of first grid then checkbox of second grid also checked that i dnt want i want to perform this operation on one grid at one time.i have attache my script also...plz help me....thanks<script type="text/javascript">        function SelectAll(ID)      &nbs...

How do I set a checkbox to checked when another checkbox in a DG row is checked?
I have a datagrid with rows of labels, textboxes, and checkboxes.  These rows show information about customers.  When a user checks one of the checkboxes, I need the other textbox to become checked as well.  When the user unchecks the checkbox, nothing should happen.  See code below.  Any ideas?  The trick is finding the checkbox control for that specific row.  Thanks!!!! <asp:GridView ID="CustomFieldsGridView" width="100%" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomizableFieldCode" DataSourceID="CustomFieldsObjectDataSource" ShowHe...

javascript: check all check box in a perticular row , when i check a checkbox i that perticuler row
Hi Friends,I have a gridview. and I am having checkboxes in all the columns and all the rows. Like it is about selecting subjects.My Problem is when I select a Checkbox in First column of any row, all the checkboxes in that particular row should also be selected.How can I do this... . I have done all checkboxes checked for column, but no idea about row.Please guide.Thanks. Hi, this can be done with the help of jQuery, a great & free javascript library. Take a look at this article: Check All Checkboxes in GridView using JQuery. Grz, Kris.Read my blog. Handy Firefox plugins for web dev...

Check One CheckBox To Check All CheckBoxes
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked. I set the AutoPostBack property of the CheckBox in the Header to True & am invoking a sub named CheckAllRows on the CheckedChanged event of this CheckBox. The CheckBox in the Header exists within the HeaderTemplate of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside within the ItemTemplate of the same TemplateColumn. This is the code (the ID of the CheckBox in the Header...

checkbox client side onclick event to manage checked status of multiple checkbox controls or multiple items in a checkboxlist
I want to use javascript to run a client side function to manage the checked state of multiple checkbox controls.  For example, if checkboxA is checked by the user, I want to uncheck checkboxB & checkboxC and check checkboxD.  I do not want to make this a postback event. Also, I'm considering using a checkboxlist control.  If I were to use a checkboxlist control with 6 list items, how would I control the checked status of the different list items based upon an onclick event for one of the list items.  An example: if checkbox list item (1) is checked, I want to unc...

A checkbox that checks the other checkboxes...
Hi everyone, I'd like to create a checkbox that checks all the checkboxes that are contained in my repeater. Does anyone know how to do this ??? I've tried some javascripts found on the net but nothing works... :'( Please help me ! It's rather urgent ! Thanks for answering ! ^^ Hello... I don't know how to make the page react when you check the box (actually I'm having trouble doing so with a dropdownlist, so if you have any idea :p) but if you add a button that you click after checking the box, you can add in the code behind file [ CheckBox1.Checked = true ] and do so to all t...

Checkbox checked at client side???
Hi, I have a datagrid. In this datagrid At each row I have a checkbox to select the whole row. The second column is a bound column and it keeps the id of the product, the third contains the name of the product and so on... I want to get the id of the product as soon as i check the checkbox. However,this should be handled in client side. Can anyone help me? Thanks... Implement the ItemDataBound event of the grid and make sure ID of the row gets passed to the client side onclick event handler of the checkbox.Bug [MCSD] I'm sorry but I could not manage to implement ItemDataB...

Checkbox List Check/Uncheck All Client Side
I have developed several web forms that include checkbox lists and radiobutton lists whose text and value fields are generated from a SQL Database table. I now would like to create a button or checkbox that will select and deselect the checkboxes on the client side. I have looked into the scripts that cycle through individual checkboxes and change their selected value based on their name, but the problem there is that checkbox lists automatically create individual names for each checkbox in the list - for example: I have a checkbox list with ID="cbxCardio" The names generated f...

How to check checkbox is checked or not dynamically....
Hai friends.... I am creating checkbox dynamically............ dim check(100) as checkbox dim cell as new tablecell check(i)=new checkbox() is there any short method to check whether non of the checkbox is checked........... Ambrose... Help me......Winners Never QuitQuitters Never Win You could do this to check if check boxes are checked If CheckBox1.Checked Then    Message.Text &= "CheckBox 1 was checked<br/>"  End If  If CheckBox2.Checked Then    Message.Text &= "CheckBox 2 was checked<br/>"  End ...

how to check if checkboxes in datalist is checked?
hi, i have a checkbox in datalist itemtemplate. i need to have a validation that checks if theres atleast 1 checkbox in datalist item that is checked, when button delete is click. Thanks   Here is code to read value of checkbox in datalist control. foreach (DataListItem item in this.dataListName.Items) { //if check box is an html control HtmlInputCheckBox chk = item.Cells[0].FindControl("checkBoxName") as HtmlInputCheckBox; //OR if checkbox is server side asp.net control CheckBox chk = item.Cells[0]....

if checkbox is checked , then all the checkboxlist should be checked
i have a checkbox list and a checkbox , i want f the checkbox is checked then all the checkboxes in the checkboxlist should be checked as well.   Please suggest , if there is any way out   Thanksneelu gupta Do u want this to be done on the client side or server side? And are these check boxes server controls or html controls??Shravan Addaypally MCP maybe this thread can help.> penny for a thought...

how to check the checkbox checked property
hi guyz i have a server side chkbox control and on the basis of it i want to enable/disable a textbox at client side, i had registered an event in my .cs class, but using java script im unable to chkeck whether the checkBox is checked or not (at client side) im doing it on  .acx control and i donot have a form object on it. i tried alot but unable to find the solution kindly tell me if any1 knows..........     thnx For a CheckBox this is all that you need. If a CheckBoxList there is a little more involved. /////////////////////////////////// aspx file///////...

gridview check if checkbox is checked
 I have a column with checkboxes in my gridview, I want to check each row if the checkbox was checked, if yes do something with the data of that row. How do I do that?I added the checkboxes the following way <asp:TemplateField>                                <ItemTemplate>                         &nb...

Web resources about - how to check all the row level checkbox when header level checkbox is checked - asp.net.client-side

Checkbox - Wikipedia, the free encyclopedia
In computing , a checkbox ( check box , tickbox , or tick box ) is a graphical user interface element ( widget ) that permits the user to make ...


XYplorer adds flat select tool, timestamping, sticky checkbox selection and improves portable device ...
... them a date previously copied to the clipboard. sc_* - *.doc matches both files beginning sc_ and those with a .doc extension. Sticky checkbox ...

Beware of checkbox marketing!
... able to sell the product at all and the company will go out of business. (sometimes in those exact words) These are the two edges of the checkbox ...

Disable Lion’s Resume Checkbox When Shutting Down [Video How-To]
One of the most annoying features in OS X Lion for me has been the little checkbox on the shutdown dialog box that states, "Reopen windows when ...

A Checkbox On Your Tax Return Helped Kill Public Campaign Funding
You already hate tax season, and as you move wearily through the cold calculations of the 1040 form, you come across a familiar checkbox. It’s ...

Google's Clever Plan to Replace CAPTCHA With a Checkbox
CAPTCHAs are an unfortunate side effect of the internet. They're those irritating collection of numbers and letters morphed into some Surrealist ...

Great news: New EEOC checkbox category emerges
"Bow-tie'n white boys"? Hey, I tried to anticipate the next expansion in ethnic categorization yesterday with my proposal for recognition of ...

Checkbox Syndrome: Why We Spend Money on Things We Don't Need
Ever been overwhelmed by the temptation to buy the latest shiny thing because it's got another checkbox in the features column? We call this ...

Magid: Google ditching CAPTCHA for 'I'm not a robot' checkbox
We need better security, but we need to find systems that are hard for bad guys to break but easy for good folks to use. Google is one of the ...

Resources last updated: 1/4/2016 1:59:40 AM