hi all,
i have used a reapeter control in which i am using checkbox in id field.I need to disable the multiple checking of checkbox.how is it possible to do. Plz help me as soon as possible.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit ChoudharyPosted Aug 23, 2010, 4:16 AM
function CheckValues(source, args)
{
//change the values of these 2 variables
//to reflect the name of your Repeater/DataGrid
//and CheckBox
var ctrl = 'repContacts';
var cbName = 'cbSelect';
//make sure that you set this with the name
//of your form
var objForm = document.form1;
var errorCount = 0;
//get the name of the controls in the list
var ctrlName = ctrl + '_ctl00_' + cbName;
var chkBox = DOMCall(ctrlName);
//check to make sure there isnt a problem
//with your Repeater/DataGrid
if(chkBox == null)
{
alert ('There was an issue checking the *'+cbName+'* check box in the *'+ctrl+'* control');
return errorCount;
}
var isChecked = false;
//very important to start at 0
var i = 0;
ctrlName = ctrl + '_ctl0' + i + '_' + cbName;
var curItem = DOMCall(ctrlName);
if(null == curItem)
{
alert ('It was null'); // something is wrong. Probably one of the 'Customize Values'
}
//start looping through the Repeater/DataGrid
while (curItem != null)
{
//to check items inside the DataGrid/Repeater
//using the != null check should keep it from getting locked up
if (curItem.checked == true)
{
isChecked = true;
}
//now check to see the value of i, if it's equal
//or greater than 10 we need to change how we look
//for the next control
if(i >= 10)
{
ctrlName = ctrl + '_ctl' + i + '_' + cbName;
}
else
{
ctrlName = ctrl + '_ctl0' + i + '_' + cbName;
}
curItem = DOMCall(ctrlName);
i += 1
}
//if nothing was selected alert the user
if (isChecked == false)
{
alert('Your need to select at least 1 contact in your list');
return false;
errorCount+=1;
}
return isChecked;
}
//function to use whatever DOM Object
//the users browser has
function DOMCall(name)
{
//Checks the DOM features available
if (document.layers) //checks document.layers
return document.layers[name];
else if (document.all) //checks document.all
return document.all[name];
else if (document.getElementById) //checks getElementById
return document.getElementById(name);
}
//sample usage in C#
Button1.Attributes.Add("onclick","return CheckValues(); return false;");