As I have check box in gridview if i dont select any one check box and if i click asp button then i have to show message to user to select check box
awaiting ur response
As I have check box in gridview if i dont select any one check box and if i click asp button then i have to show message to user to select check box
awaiting ur response
If you want to do this client side you could use a library like jQuery to iterate through the checkboxes.
If you want to do this server side, you will need to reenumerate the controls on postback, and check the Checked value. Alternatively if this GridView binds to a DataSource, check the posted back values within the DataSource.
Should be something like you need...
Boolean Selected = false;
for (int count = 0; count < grd.Rows.Count; count++)
{
if (((CheckBox)grd.Rows[count].FindControl("yourCheckbox")).Checked)
{
Selected = true;
}
}
if (Selected == false)
{
//your message goes here.
}
if you need javascript code...
function CheckIfSelect() {
var frm = document.forms[0];
var Selected=false;
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox") {
if(frm.elements[i].checked)
{
Selected=true;
break;
}
}
if(Selected==false)
{
//your message goes here
}
}
}