views:

17

answers:

1

in a grid view how can i apply a validator to check if any of grid view rows with check box are checked or not. i did it using the custom validator like this but giving the error "Control 'GridView1' referenced by the ControlToValidate property of 'gridCheck' cannot be validated. " following is my code what should i do please suggest me the alternate

protected void gridCheck_ServerValidate(object source, ServerValidateEventArgs args)
    {
        foreach (GridView row in GridView1.Rows) 
        { 
            CheckBox cb = (CheckBox)row.FindControl("Chek");
            if (cb != null && cb.Checked)
            {
                args.IsValid = true;
                return;
            }
            else args.IsValid = false;
        }
    }
A: 

You'd have to add a template field column. Set the gridview to edit templates mode. (in your designer). You can drag and drop controls as usual and set their ids etc. Add your validator control, and set the id.

deostroll
my project don't require to turn grid view in edit mode in that case how can i do this. Y direct as i did above doesn't work please let me know what else can i do ?
NoviceToDotNet
I meant "edit Templates" mode, in the designer...I am not talking about enabling "edit button" and all for each row. Click on the gridview's smart tag. Plz check this link if you are finding it difficult finding the smart tag... http://aspnetgoodies.files.wordpress.com/2007/12/grid-view-smart-tag.jpg
deostroll