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

get a control in an itemtemplate with javascript

1 Answer 273 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gozcelik
Top achievements
Rank 1
gozcelik asked on 04 Dec 2014, 11:20 AM
Hi,
There tons of sample for "get a control in an itemtemplate with javascript". But I have a problem.

I have a grid like below. When cbAllCanSelect is checked, I try to find all checkboxes in a column and check them all.

<telerik:RadGrid ID="rgOptions" runat="server" AutoGenerateColumns="False"
            ResolvedRenderMode="Classic" AllowMultiRowEdit="True">
            <MasterTableView>
                <Columns>
                    <telerik:GridBoundColumn DataField="KARAKTERTANIM"
                        FilterControlAltText="Filter column column" HeaderText="Option"
                        UniqueName="column">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn FilterControlAltText=""
                        HeaderText="Selection" UniqueName="TemplateColumn">
                        <ItemTemplate>
                            <asp:HiddenField ID="hfKarakter" runat="server" Value = '<%# Eval("KARAKTER") %>'/>
                            <asp:CheckBox ID="cbCanSelect" runat="server"   Checked = '<%#bool.Parse( Eval("CANSELECT").ToString()) %>'/>
                        </ItemTemplate>
                        <HeaderTemplate>
                            <telerik:RadButton ID="cbAllCanSelect" runat="server" ToggleType="CustomToggle" ButtonType="ToggleButton"
               AutoPostBack="false" onclienttogglestatechanged="toggleCanSelectCheckBoxes">
               <ToggleStates>
                    <telerik:RadButtonToggleState Text="" PrimaryIconCssClass="rbToggleCheckbox">
                    </telerik:RadButtonToggleState>
                    <telerik:RadButtonToggleState Text=""  PrimaryIconCssClass="rbToggleCheckboxFilled">
                    </telerik:RadButtonToggleState>
                    <telerik:RadButtonToggleState Text=""  PrimaryIconCssClass="rbToggleCheckboxChecked">
                    </telerik:RadButtonToggleState>
               </ToggleStates>
          </telerik:RadButton>
                        </HeaderTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>



My script (ignore button toogle and just check them all):

function toggleCanSelectCheckBoxes(sender, args) {
            //alert(sender.get_selectedToggleState().get_index());
 
            var dataItems = $find('<%=rgOptions.ClientID%>').get_masterTableView().get_dataItems();
            for (var i = 0; i < dataItems.length; i++) {
                var cb = dataItems[i].findControl("cbCanSelect");
                alert(cb);
                if (cb != null)
                    cb.checked = true;
            }
        }



I cant find "cbCanSelect". "cb" is always return null.

What is my mistake?

Thanks a lot.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 09 Dec 2014, 12:07 PM
Hello gozcelik,

Try replacing the findControl method with findElement for non-Telerik controls. Please note that you can use the built-in selection functionality provided by RadGrid to achieve this requirement:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/selecting/row-selection/defaultcs.aspx

Hope this helps.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
gozcelik
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or