This is a migrated thread and some comments may be shown as answers.

[Solved] Making adding items to Grid mandatory

1 Answer 126 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
scrut
Top achievements
Rank 1
scrut asked on 06 Jun 2008, 11:26 AM
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.

1 Answer, 1 is accepted

Sort by
0
Baatezu
Top achievements
Rank 2
answered on 08 Jun 2008, 05:13 PM
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. :)
Tags
General Discussions
Asked by
scrut
Top achievements
Rank 1
Answers by
Baatezu
Top achievements
Rank 2
Share this question
or