在Telerik RadGrid中调用grid.get选定项时的Javascript TypeError

时间:2014-09-03 15:07:35

标签: javascript telerik telerik-grid

我有RadGrid ClientSelectColumn。当用户进行选择并单击按钮时,我需要获取所有选定的项目。根据{{​​3}},此代码应该有效。我已经不得不使用getElementById,因为$find由于某种原因无效。

function GetSelectedItems() {
        var grid = document.getElementById("<%= RadGrid1.ClientID %>");
        var selectedRows = grid.get_selectedItems(); //ERROR
        var selectedLabIDs = [];

        for (var i = 0; i < selectedRows.length; i++) {
            var selectedLabID = selectedRows[i].getDataKeyValue("LabID");
            selectedLabIDs.push(selectedLabID);
        }

        var list = selectedLabIDs.join('|');

        MergePDF(list);
    }

当按钮调用GetSelectedItems()时,我得到了这个:

  

TypeError:grid.get_masterTableView不是函数

为什么会这样?

编辑:这是RadGrid和页面其余部分的标记。

<telerik:RadScriptManager runat="server" ID="RadScriptManager1">
    <Scripts>
        <%--Needed for JavaScript IntelliSense in VS2010--%>
        <%--For VS2008 replace RadScriptManager with ScriptManager--%>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
    </Scripts>
</telerik:RadScriptManager>

<telerik:RadSkinManager ID="QsfSkinManager" runat="server" Skin="Metro" />
<telerik:RadFormDecorator ID="QsfFromDecorator" runat="server" DecoratedControls="All" EnableRoundedCorners="false" />
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">

<telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server" AutoGenerateColumns="False"
    AllowSorting="True"
    AllowMultiRowSelection="true"
    AllowPaging="True"
    OnNeedDataSource="RadGrid1_NeedDataSource" OnDataBound="RadGrid1_DataBound">
    <HeaderStyle ForeColor="White" HorizontalAlign="Center" />
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
        <ClientEvents OnRowSelected="RowSelected" />
    </ClientSettings>
    <MasterTableView DataKeyNames="CustReview, MachineName, LabID, MachCond, LubCond, PointID, CustEQUID, CANote, rptNotes, Feedback, ReportType" ClientDataKeyNames="LabID">
        <Columns>
            <telerik:GridBoundColumn DataField="CustReview" HeaderText="Customer Review" DataType="System.String" />
            <telerik:GridBoundColumn DataField="PlantName" HeaderText="Plant Name" DataType="System.String" />
            <telerik:GridBoundColumn DataField="MachineName" HeaderText="Machine" DataType="System.String" />
            <telerik:GridBoundColumn DataField="CustEQUID" HeaderText="Customer ID" DataType="System.String" />
            <telerik:GridBoundColumn DataField="LabID" HeaderText="Report #" DataType="System.Int32" />
            <telerik:GridClientSelectColumn UniqueName="SelectColumn" />
            <telerik:GridBoundColumn DataField="ReportType" HeaderText="Type" DataType="System.String" />
            <telerik:GridImageColumn HeaderText="Mach" UniqueName="MachineConditionImage" />
            <telerik:GridImageColumn HeaderText="Lub" UniqueName="LubricantConditionImage" />
            <telerik:GridDateTimeColumn DataField="ReceivedDate" DataFormatString="{0:d}" UniqueName="ReceivedDateColumn" HeaderText="Rec. Date" />
            <telerik:GridHyperLinkColumn HeaderText="Feedback" UniqueName="FeedbackColumn" />
            <telerik:GridHyperLinkColumn HeaderText="Corrective Action" UniqueName="CorrectiveActionColumn" />
            <telerik:GridImageColumn HeaderText="Notes" UniqueName="NotesColumn" />

            <%--Hidden Columns --%>
            <telerik:GridBoundColumn DataField="PointID" DataType="System.Int32" Visible="false" />
            <telerik:GridBoundColumn DataField="MachCond" DataType="System.Int32" Visible="false" />
            <telerik:GridBoundColumn DataField="LubCond" DataType="System.Int32" Visible="false" />
            <telerik:GridBoundColumn DataField="rptNotes" DataType="System.String" Visible="false" />
            <telerik:GridBoundColumn DataField="Feedback" DataType="System.String" Visible="false" />
            <telerik:GridBoundColumn DataField="CANote" DataType="System.String" Visible="false" />
            <%--Hidden Columns --%>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

<input type="hidden" id="SelectList" runat="server" />
<input type="hidden" id="PlantID" runat="server" />
<input type="hidden" id="RouteID" runat="server" />
<input type="hidden" id="NumberOfResults" runat="server" />

</telerik:RadAjaxPanel>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>

1 个答案:

答案 0 :(得分:0)

您看到grid.get_masterTableView不是函数的错误的原因是因为您的var grid不是有效的RadGrid。您可以像这样获得网格:

var grid = $find("RadGrid1");