Skip to content

useful links

December 4, 2012

http://www.mredkj.com/vbnet/CheckBoxListItemDisable.html

http://www.codeproject.com/Articles/8105/ASP-NET-C-Disable-Enable-ListItems

http://www.aspdotnet-suresh.com/2012/09/jquery-validate-checkboxlist-in-aspnet.html

http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode.aspx

—-

<script type = “text/javascript”>
var atLeast = 2
function Validate()
{
var CHK = document.getElementById(“<%=CheckBoxList1.ClientID%>”);
var checkbox = CHK.getElementsByTagName(“input”);
var counter=0;
for (var i=0;i<checkbox.length;i++)
{
if (checkbox[i].checked)
{
counter++;
}
}
if(atLeast>counter)
{
alert(“Please select atleast ” + atLeast +  ” item(s)”);
return false;
}
return true;
}
</script>
<script type = “text/javascript”>
function GetSelectedItem()
{
var CHK = document.getElementById(“<%=CheckBoxList1.ClientID%>”);
var checkbox = CHK.getElementsByTagName(“input”);
var label = CHK.getElementsByTagName(“label”);
for (var i=0;i<checkbox.length;i++)
{
if (checkbox[i].checked)
{
alert(“Selected = ” + label[i].innerHTML);
}
}
return false;
}
</script>

<div>
<asp:CheckBoxList ID=”CheckBoxList1″ runat=”server”>
<asp:ListItem Text = “One” Value = “1”></asp:ListItem>
<asp:ListItem Text = “Two” Value = “2”></asp:ListItem>
<asp:ListItem Text = “Three” Value = “3”></asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:Button ID=”Button1″ runat=”server” Text=”Validate” OnClientClick = “return Validate()” />
<asp:Button ID=”Button2″ runat=”server” Text=”SelectedItem” OnClientClick = “return GetSelectedItem()” />

</div>

————————-

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: