Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhimanyu K VatsaRank #14 · 51.7K reputationPosted Apr 25, 2011, 2:05 AM EDT
most probably we uses javascript for this but there are couple of ways, use this if you wish via javascript:
type="text/javascript"> $('table[id$=GridView1]').find('input:checkbox').click(function(e) { var tr = $(this).closest('tr'); var lblError = tr.find('span[id$=lblError]'); if (tr.find('input:checkbox:checked').length == 3) { lblError.html('Not possible to select more than 2.'); this.checked = false; } else { lblError.html(''); } });visit there for more:
http://wikiaspnet.wordpress.com/2008/08/22/validate-checkbox/
Ankit NandekarRank #703 · 3.4K reputationPosted Apr 25, 2011, 2:08 AM EDT
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
int c = 0;
protected void Page_Load(object sender, EventArgs e)
{
lblMsg.Visible = false;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control chkcontrol in form1.Controls)
{
if (chkcontrol.GetType().ToString() == "System.Web.UI.WebControls.CheckBox")
{
if (((CheckBox)chkcontrol).Checked == true)
{
c++;
// write code when check box checked
}
else
{
if (c == 0)
{
lblMsg.Visible = true;
lblMsg.Text = "please select CheckBox";
}
}
}
}
}
}
Sahil Jani196 reputationPosted Apr 25, 2011, 2:11 AM EDT
Most probably you wil find your answer on the following link :::
http://weblogs.asp.net/samirgeorge/archive/2009/05/02/checkboxlist-client-side-validation-using-jquery.aspx