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

Get GridTemplateColumn control client-side

3 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 11 Aug 2008, 04:40 PM
I'm sure someone can quickly point me in the right direction, but I've been tearing my hair out (something I can ill afford to do).

I have a RadGrid with columns arranged
GridTemplateColumn\GridBoundColumn\GridBoundColumn\GridTemplateColumn
Column 1 has an ASP CheckBox, column 4 an ASP DropDownList.

If the checkbox is unchecked, the dropdown is disabled; checking enables the dropdown. That's all good.

I also have a RadContextMenu on the Grid. I would like to enable or disable the menu items dependent on the state of the checkbox. This would need to be client-side JavaScript, within the OnClientItemClicked event (that's where I inspect the Menu item to see what I need to do).

I haven't been able to find anything about how to access a control within a GridTemplateColumn (maybe I've just not been looking in the right place?). I can get at values if I add them to ClientDataKeyNames, but that's not appropriate.

I've managed a workaround using a hidden field, but I'd like the code to simply check the enabled state, for reliability reasons (checking the value of a certain field isn't quite as robust as I'd wish).

paul

3 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 14 Aug 2008, 11:41 AM
Hello Paul,

You can use the getCellByColumnUniqueName method, to get a reference to the cell hosting the menu.
Let me know if this is a feasible approach for you.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Paul
Top achievements
Rank 1
answered on 14 Aug 2008, 01:04 PM

Hi Yavor,

Thanks for that - you have got me a little further and a subsequent Forum search has come up with an answer that I can use. Your response assumes that I am dealing with the first row, so I have coded the following JavaScript, which seems to do the trick:

function RadGrid1_OnRowContextMenuHandler(sender, args)
{ args.get_tableView().selectItem($get(args.get_id())); $find("<%= RadGrid1ContextMenu.ClientID %>").show(args.get_domEvent());
var menu = $find("<%= RadGrid1ContextMenu.ClientID %>");
var editmenuitem = menu.findItemByValue("Edit");               
//default position
editmenuitem.disable();
var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
var i = args.get_itemIndexHierarchical();
var cell = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[i], "GridTemplateColumnUniqueName").innerHTML;
var checked = cell.search(/checked/i);

if(checked > -1)
    editmenuitem.enable();
}

Well, I've compressed it a little, but you can see my working. I hope that this will prove useful for someone else (and that the formatting is ok).

Cheers

paul

0
Yavor
Telerik team
answered on 19 Aug 2008, 06:16 AM
Hello Paul,

I am glad that the functionality is working as expected at your end.
Thank you for sharing the code with the community.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Paul
Top achievements
Rank 1
Share this question
or