Gregor Jaksa
Top achievements
Rank 1
Gregor Jaksa
asked on 31 Mar 2008, 07:05 AM
Is there any client side event fired right before OnItemCommand event that has griddataitem or tableview argument ?
The reason i need this is that i would like to check if user selected any rows and if not i would like to fire up an dialog notifying user to select at least one row.
Currently im doing this on the server side on OnItemCommand event, if there's no rows selected i register startup script that shows the dialog, but i dont like it :)
Thx
The reason i need this is that i would like to check if user selected any rows and if not i would like to fire up an dialog notifying user to select at least one row.
Currently im doing this on the server side on OnItemCommand event, if there's no rows selected i register startup script that shows the dialog, but i dont like it :)
Thx
3 Answers, 1 is accepted
0
Hello Gregor,
One other option is to assign onclick client side handlers for the elements in the commandItem, and show the dialog. I hope that this is a good alternative for you.
All the best,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
One other option is to assign onclick client side handlers for the elements in the commandItem, and show the dialog. I hope that this is a good alternative for you.
All the best,
Yavor
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Gregor Jaksa
Top achievements
Rank 1
answered on 02 Apr 2008, 08:06 AM
That's what i was thinking, but i don't know how to get detailtableview for the command clicked so that i can check if any of its items is checked.
0
Gregor Jaksa
Top achievements
Rank 1
answered on 03 Apr 2008, 05:23 AM
I found the solution :)
I attach to Init event of the LinkButton control and search for griddataitem to get ownertableview.ClientId and also to set ClientClick property which executes javascript with ownertableid as argument.
Below is the sample code if anyone else is interested:
C#
| protected void documentsLinkButton_Init(object sender, EventArgs e) | |
| { | |
| LinkButton linkButton = sender as LinkButton; | |
| if (linkButton == null) | |
| return; | |
| GridTableView gridTableView = null; | |
| Control control = linkButton; | |
| while (control.Parent != null) | |
| { | |
| gridTableView = control as GridTableView; | |
| if (gridTableView != null) | |
| break; | |
| control = control.Parent; | |
| } | |
| if (gridTableView != null) | |
| linkButton.OnClientClick = String.Format("return checkForSelectedItems('{0}', 'DocumentsCheckBox')", gridTableView.ClientID); | |
| } |
Javascript
| function checkForSelectedItems(detailTableId, checkBoxColumnName) | |
| { | |
| var detailTable = $find(detailTableId); | |
| if (detailTable == null) | |
| return false; | |
| var dataItems = detailTable.get_dataItems(); | |
| for (var i = 0; i < dataItems.length; i++) | |
| { | |
| var checkBoxCell = detailTable.getCellByColumnUniqueName(dataItems[i], checkBoxColumnName); | |
| if (checkBoxCell == null) | |
| continue; | |
| if (checkBoxCell.childNodes[0].checked) | |
| return true; | |
| } | |
| alert('No items selected. You need to select at least one item.'); | |
| return false; | |
| } |