I have a page with a "Save" button which should remain inactive until all mandatory fields have been filled with data. One of those mandatory fields is a RadGrid which uses the built-in insert/edit/delete-mechanisms.
How can I make it mandatory for the user to add at least one item?
Thanks
s.
I haven't done it with a radgrid, but I can give you a quick brain storm idea, it might be a little brute force-ish. I've only been working with the controls for a few months, so I'm not a ninja with them yet and there may be a more elegant solution that I am unaware of.
What I'd try is:
Save button enabled and calls a javascript function before doing the postback. I'm not sure if a Validator can be applied to a rad grid, which is why I suggest the javascript on save.
You will need to know how many entries start in the radgrid (I'm gonna roll with 0 for now)
In the javascript do something like
function CheckGrid()
{
var DataItems = $find("<%= RadGrid1.MasterTableView.ClientID %>").get_dataItems();
if(DataItems.length > 0)//Here 0 is the number of items it starts with
{
alert("You must enter ...");
return false;
}
return true;
}
The javascript call from the button will need to be set up something like
onclick="if(!CheckGrid())return false;" That will prevent it from doing a postback if the function returns false;
It might be possible to set up a RequiredFieldValidator and not assign it a control and in the javascript set the IsValid, but I haven't done that yet, so not sure.
This is all from memory and using the telerik demo's and help files - so there is probably a couple 'bugs' in it. :)
I hope this helps you find something of a solution until someone more better than I at this gives a more better solution. :)