function checkBoxselectedornot()
{
var frm=document.forms['aspnetForm'];
var flag=false;
for(var i=0;i<document.forms[0].length;i++)
{
if(document.forms[0].elements[i].id.indexOf('chkDownloadSelectedEvent')!=-1)
{
if(document.forms[0].elements[i].checked)
{
flag=true
}
}
}
if (flag==true)
{
return true
}else
{
alert('Please select at least one Event.')
return false
}
}
jayaravi
Member
7 Points
36 Posts
how to validate checkboxlist inside gridview using asp.net
Mar 12, 2012 10:07 AM|LINK
I want to check checkboxlist item is checked or not,if not then it will show message on button click
pls help
thanks in advance
Honnappa
Participant
1112 Points
534 Posts
Re: how to validate checkboxlist inside gridview using asp.net
Mar 12, 2012 10:14 AM|LINK
try this
StringCollection idCollection = new StringCollection(); string strID = string.Empty; for (int i = 0; i < Gridview1.Rows.Count; i++) { // Programmatically access the CheckBox from the TemplateField CheckBox cb = (CheckBox)Gridview1.Rows[i].Cells[0].FindControl("checkseleted"); if (cb.Checked) { //Checked } else { //UnChecked } }My Profile
raminsha
Member
565 Points
130 Posts
Re: how to validate checkboxlist inside gridview using asp.net
Mar 12, 2012 10:15 AM|LINK
You can use FindControl to get any controls inside gridview
srinanthuram
Contributor
6800 Points
1549 Posts
Re: how to validate checkboxlist inside gridview using asp.net
Mar 12, 2012 10:22 AM|LINK
hi
see this url
http://www.codeproject.com/Articles/23124/Client-Side-Validation-for-the-CheckBoxes-Inside-a
or
try this
function checkBoxselectedornot() { var frm=document.forms['aspnetForm']; var flag=false; for(var i=0;i<document.forms[0].length;i++) { if(document.forms[0].elements[i].id.indexOf('chkDownloadSelectedEvent')!=-1) { if(document.forms[0].elements[i].checked) { flag=true } } } if (flag==true) { return true }else { alert('Please select at least one Event.') return false } }karthick mei...
Member
2 Points
2 Posts
Re: how to validate checkboxlist inside gridview using asp.net
Jan 09, 2013 03:47 AM|LINK
<asp:CheckBoxList ID="chkJobCategoryList" runat="server" RepeatLayout="Flow">
</asp:CheckBoxList>
<asp:CustomValidator runat="server" ID="CustomValidator1" SetFocusOnError="true" ClientValidationFunction="ValidatecategoryList"
ErrorMessage="" CssClass="validator" ValidationGroup="vgJobPosition" >Please Select Atleast one Module</asp:CustomValidator>
<script language="javascript" type="text/javascript">
function ValidatecategoryList(sender, args) {
var chkListModules1 = document.getElementById('<%= chkJobCategoryList.ClientID%>');
var chkListinputs1 = chkListModules1.getElementsByTagName("input");
for (var i = 0; i < chkListinputs1.length; i++) {
if (chkListinputs1[i].checked) {
args.IsValid = true;
return;
}
}
args.IsValid = false;
}
</script>