How to add a checkbox controlin the header of a DataGrid control
-
1. How to add a checkbox in the header(next to ‘Select All’) of the datagrid control. 2. If I select the header checkbox then all the other checkboxes should be automatically checked. 3. After the above thing is achieved,if I uncheck any of the checkboxes ,the header checkbox must be unchecked automatically. Please kindly help me in this issue Thanks a lot arun
-
1. How to add a checkbox in the header(next to ‘Select All’) of the datagrid control. 2. If I select the header checkbox then all the other checkboxes should be automatically checked. 3. After the above thing is achieved,if I uncheck any of the checkboxes ,the header checkbox must be unchecked automatically. Please kindly help me in this issue Thanks a lot arun
This is the java script for select-all /* Function for check all the check boxes in the Grid*/ function SelectAllCheckboxes(spanChk) { // Added as ASPX uses SPAN for checkbox var oItem = spanChk.children; var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0]; xState=theBox.checked; elm=theBox.form.elements; for(i=0;i
-
1. How to add a checkbox in the header(next to ‘Select All’) of the datagrid control. 2. If I select the header checkbox then all the other checkboxes should be automatically checked. 3. After the above thing is achieved,if I uncheck any of the checkboxes ,the header checkbox must be unchecked automatically. Please kindly help me in this issue Thanks a lot arun
hi Arun, 1.you need a Template Column for this . Add a template column to your datagrid. put two checkboxes in the
Header
andItemTemplate
column. 2.for the second query you can do it in two ways. a.if you want to do it in the client side....... you have to put your code in theonclick
event handler of the header checkbox.putonclick="checkingboxes()"
herecheckingboxes()
is the client side Javascript function.function checkingboxes() { dgChkItem.checked=true;// dgChkItem is the id of ItemTemplate checkbox. }
b. if you want to do it in the server side..... make theAutoPostBack
property of the header checkbox totrue
. In theCheckedChanged
event handler put code for checking theItemTemplate
checkbox in thedgChkHead_CheckedChanged(....)
event pute.Item.FindControl("dgChkItem").checked=true;
Tirthadip Live life to the fullest