1

我从下面的链接中复制了代码 Check all CheckBoxes in Telerik nested Grid in C#

当我运行代码时,我得到了这个错误:

0x800a01b6 - Microsoft JScript runtime error: Object doesn't support this property or method

并且在'checkAll(this, gridToCheckAll);'带有错误的动态运行代码中突出显示。

任何帮助,将不胜感激。

<script>
var gridToCheckAll = '<%= rgFiles.ClientID %>';

    function checkAll(sender, containerID) {
        var checked = sender.checked;
        var container = document.getElementById(containerID);
        var checkboxes = container.getElementsByTagName('input');
        for (var i = 0, l = checkboxes.length; i < l; i++) {
            if (checkboxes[i] != sender && !checkboxes[i].disabled)
                checkboxes[i].checked = checked;
        }
    }
</script>

<telerik:RadGrid id="rgFiles" runat="server" HorizontalAlign="NotSet" BackColor="darkgray"
    AllowPaging="True" PageSize="50" AllowSorting="True"
    EnableEmbeddedScripts="true" 
    OnNeedDataSource="rgFiles_NeedDataSource"  
    OnItemCommand="rgFiles_ItemCommand" 
    OnItemDataBound="rgFiles_ItemDataBound" 
    OnItemEvent="rgFiles_ItemEvent"
    AllowMultiRowSelection="true" Skin="" 
    AllowFilteringByColumn="true" EnableLinqExpressions="false" >
    <MasterTableView  HorizontalAlign="NotSet" AutoGenerateColumns="false" AllowSorting="True"
        Font-Size="7pt" AllowCustomSorting="true" CellPadding="2" CellSpacing="1" BorderWidth="0px"
        TableLayout="Fixed" AlternatingItemStyle-Wrap="false" ItemStyle-Wrap="false" 
        CommandItemStyle-Wrap="false" >
        <FooterStyle CssClass="datagrid-footerstyle" HorizontalAlign="Right" />
        <ItemStyle CssClass="datagrid-itemstyle" Wrap="false" Font-Size="XX-Small" Height="15px"/>
        <EditItemStyle BackColor="#2461BF" />
        <PagerStyle BackColor="#E0E0E0" ForeColor="DimGray" HorizontalAlign="Left" Mode="NextPrevAndNumeric"
            NextPageText="next" PrevPageText="prev" AlwaysVisible="True" />
        <HeaderStyle CssClass="datagrid-headerstyle" ForeColor="White" />
        <FilterItemStyle BackColor="#a9a9a9" />
        <AlternatingItemStyle CssClass="datagrid-alternatingitemstyle" />
        <ExpandCollapseColumn Visible="False">
            <HeaderStyle Width="19px" />
        </ExpandCollapseColumn>
        <RowIndicatorColumn Visible="False">
            <HeaderStyle Width="20px" />
        </RowIndicatorColumn>
        <Columns>
            <telerik:GridTemplateColumn SortExpression="Reviewed"  DataField="Reviewed" HeaderText="<input type='checkbox' id='checkAll' onclick='checkAll(this, gridToCheckAll);'>" 
                UniqueName="Reviewed" AllowFiltering="false" >
                <ItemTemplate>
                    <asp:CheckBox ID="cbReviewed" runat="server" OnCheckedChanged="cbReviewed_CheckedChanged" />
                </ItemTemplate>
                <ItemStyle Wrap="False" HorizontalAlign="Center" VerticalAlign="Top"></ItemStyle>
                <HeaderStyle Width="50px"></HeaderStyle>
            </telerik:GridTemplateColumn>
4

2 回答 2

4

也许您应该使用 Telerik:GridClientSelectColumn 代替您的 templateColumn,Telerik 具有您正在寻找的内置功能。

API:http ://www.telerik.com/help/aspnet-ajax/grid-column-types.html

<radgrid...>
<masterTableView ... >
   <columns>
      <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn">
           <HeaderStyle Width="35px" />
       </telerik:GridClientSelectColumn>
    </columns>
</MasterTableView>
 <ClientSettings>
       <ClientEvents OnRowSelected="RowSelected" OnRowDeselected="RowDeselected"/>
 </ClientSettings>
</radgrid>


       function RowDeselected(sender, eventArgs){
            //your code
        }

        function RowSelected(sender,eventArgs)
        {
            var MasterTable = sender.get_masterTableView();
            var selectedRows = MasterTable.get_selectedItems();
            var selectedRowsCount = selectedRows.length;
            //etc
        }
于 2012-12-17T21:10:37.910 回答
0

我知道我来不及回答最初的问题。但仍然想为其他开发人员提供我的反馈。

在这两个地方将您的 java 脚本方法名称从 checkAll() 更改为其他任何名称,您将不会看到这个讨厌的 JS 错误:)

于 2013-06-06T19:16:12.003 回答