I had written a j.s for onclick event and even though i had clicked it.
This was the code that i used to call the j.s
chk.Attributes.Add("onclick", "javascript:Temp('" & CType(dgi.FindControl("ddMapToColumn"), DropDownList).ClientID & "'); return false")
But, to my surprise, even after checking the checkbox, the tick mark on the check box wasn't coming.
The reason for which is the "return false;" statement.
This was something that i learned after googling
Thursday, March 20, 2008
DataGrid + On Click of Check box, Enable or Disable a Drop Down
This is how it goes..
Add Attributes to the checkbox in item data bound
For Each dgi In dgCol.Items
Dim chk As CheckBox = CType(dgi.FindControl("chkSelect"), CheckBox)
chk.Attributes.Add("onclick", "javascript:Temp('" & CType(dgi.FindControl("ddMapToColumn"), DropDownList).ClientID & "');")
Next
The Java script that does the Enabling / Disabling is as follows..
function Temp(drpdown)
{
document.getElementById(drpdown).disabled = !document.getElementById(drpdown).disabled;
}
Nothing much is required apart from this and the job is done !!
Add Attributes to the checkbox in item data bound
For Each dgi In dgCol.Items
Dim chk As CheckBox = CType(dgi.FindControl("chkSelect"), CheckBox)
chk.Attributes.Add("onclick", "javascript:Temp('" & CType(dgi.FindControl("ddMapToColumn"), DropDownList).ClientID & "');")
Next
The Java script that does the Enabling / Disabling is as follows..
function Temp(drpdown)
{
document.getElementById(drpdown).disabled = !document.getElementById(drpdown).disabled;
}
Nothing much is required apart from this and the job is done !!
Retrieve Query String Parameters using Javascripts
Retrieve Query String Parameters using Javascripts
Parameters are coming, but its giving an obj not found error, Need to Check that out
""
Parameters are coming, but its giving an obj not found error, Need to Check that out
""
Data Grid + Checkboxes...
This is Useful when you have a Grid and u need to use javascripts for Each element , in this ex its Check Box
Here is the ASP code
//
// this html tag adds checkbox to header
//
onclick="DGSelectOrUnselectAll('DataGrid1',this,'chkDel')" >
//
// this html tag adds checkbox to datagrid
Below is the Java Script
//-------------------------------------------------------
//this is to select or unselect the datagrid check boxes
function DGSelectOrUnselectAll(grdid,obj,objlist){
//this function decides whether to check or uncheck all
if(obj.checked)
DGSelectAll(grdid,objlist)
else
DGUnselectAll(grdid,objlist)
}
//----------
function DGSelectAll(grdid,objid){
//.this function is to check all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=true;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}//--------------
function DGUnselectAll(grdid,objid){
//.this function is to uncheckcheck all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=false;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}
//-------------------------------------------------------
THIS IS USEFUL TO CHECK OR UNCHECK CHECKBOXES IN A GRID.
PS: THIS ONLY AFFECTS THE CURRENT PAGE CONTENTS OF THE GRID.
IF YOU NEED THE SAME TO AFFECT ALL OTHER PAGES, THEN WE NEED TO CUSTOMISE THE ABOVE CODE
BY ADDING A HIDDEN VARIABLE AND SETTING IT TO SOME VALUE WHICH IF SET, THEN CHECKS ALL CHECK BOXES
WHEN WE LOAD THE PAGE.
Here is the ASP code
//
// this html tag adds checkbox to header
//
onclick="DGSelectOrUnselectAll('DataGrid1',this,'chkDel')" >
//
// this html tag adds checkbox to datagrid
Below is the Java Script
//-------------------------------------------------------
//this is to select or unselect the datagrid check boxes
function DGSelectOrUnselectAll(grdid,obj,objlist){
//this function decides whether to check or uncheck all
if(obj.checked)
DGSelectAll(grdid,objlist)
else
DGUnselectAll(grdid,objlist)
}
//----------
function DGSelectAll(grdid,objid){
//.this function is to check all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=true;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}//--------------
function DGUnselectAll(grdid,objid){
//.this function is to uncheckcheck all the items
var chkbox;
var i=2;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
while(chkbox!=null){
chkbox.checked=false;
i=i+1;
chkbox=document.getElementById(grdid +
'__ctl' + i + '_' + objid);
}
}
//-------------------------------------------------------
THIS IS USEFUL TO CHECK OR UNCHECK CHECKBOXES IN A GRID.
PS: THIS ONLY AFFECTS THE CURRENT PAGE CONTENTS OF THE GRID.
IF YOU NEED THE SAME TO AFFECT ALL OTHER PAGES, THEN WE NEED TO CUSTOMISE THE ABOVE CODE
BY ADDING A HIDDEN VARIABLE AND SETTING IT TO SOME VALUE WHICH IF SET, THEN CHECKS ALL CHECK BOXES
WHEN WE LOAD THE PAGE.
Subscribe to:
Posts (Atom)
