访问radgrid内部的链接按钮给出错误

时间:2012-01-19 15:50:26

标签: asp.net telerik radgrid

我正在尝试从javascript访问radgrid控件(linkbutton)。我得到一个null定义的错误。下面是我的javascript和radgrid。 radgrid位于radpanel内部,也是我调用javascript后面的代码。

<script>
 function warningMessage(rowIndex) {

            debugger;
            var dataItems = $find('<%= RadPanelBar1.Items[0].Items[0].FindControl("RadGrid_MCLIDPicker").ClientID %>').get_masterTableView().get_dataItems();

        -- getting null error in the above line    
            }

    </script>

我的radgrid在

之下
 <telerik:RadPanelBar ID="RadPanelBar1" runat="server" Width="1500px" BackColor="#E6E6E6"
    ExpandMode="MultipleExpandedItems">
    <Items>
        <telerik:RadPanelItem runat="server" Text="ID Picker" Expanded="true">
            <Items>
                <telerik:RadPanelItem Text="" Expanded="true">
                    <ItemTemplate>
                        <table>


                            <tr>
                                <td>
                                    <telerik:RadGrid ID="RadGrid_IDPicker" AllowSorting="false"  AllowPaging="false"
                                        runat="server" GridLines="None"  Width="1500px" Visible="false">
                                        <MasterTableView RetrieveAllDataFields="true" AutoGenerateColumns="false" DataKeyNames="ID" EnableViewState="true" ClientDataKeyNames="ID"  >
                                            <Columns>
                                                <telerik:GridTemplateColumn UniqueName="TemplateLinkColumn" AllowFiltering="false"
                                                    HeaderText="ID">
                                                    <ItemTemplate>

                                                        <asp:LinkButton ID="LinkButton1"  runat="server"  OnClick="ID_Link_Click" Text='<%#Bind("ID") %>'></asp:LinkButton>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>

                                            </Columns>
                                        </MasterTableView>
                                        <PagerStyle Mode="NextPrevAndNumeric" />
                                    </telerik:RadGrid>
                                </td>
                            </tr>
                        </table>
                        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                            <AjaxSettings>
                                <telerik:AjaxSetting AjaxControlID="radBtn_Search">
                                    <UpdatedControls>
                                        <telerik:AjaxUpdatedControl ControlID="RadGrid_IDPicker" LoadingPanelID="LoadingPanel1" />
                                    </UpdatedControls>
                                </telerik:AjaxSetting>

                                <telerik:AjaxSetting AjaxControlID="ID_Link">
                                    <UpdatedControls>
                                        <telerik:AjaxUpdatedControl ControlID="RadGrid_IDPicker" LoadingPanelID="LoadingPanel1" />
                                    </UpdatedControls>
                                </telerik:AjaxSetting>
                            </AjaxSettings>
                        </telerik:RadAjaxManager>
                    </ItemTemplate>
                </telerik:RadPanelItem>
            </Items>
        </telerik:RadPanelItem>
    </Items>     
</telerik:RadPanelBar>

我的代码背后是

  protected void ID_Link_Click(object sender, EventArgs e)
     {
         try
         {

           LinkButton btn = (LinkButton)sender;
             GridDataItem row = (GridDataItem)btn.NamingContainer;
             ScriptManager.RegisterStartupScript(Page, this.GetType(), "message", string.Format("warningMessage('{0}');", row.ItemIndex), true);


}
catch()
{

3 个答案:

答案 0 :(得分:1)

我必须得到radpaelbar的参考,这就是我做的方式

   var dataItems = $find('<%= RadPanelBar1.Items[0].Items[0].FindControl     ("RadGrid_IDPicker").ClientID %>').get_masterTableView().get_dataItems();

答案 1 :(得分:0)

我怀疑你需要获得对PanelBar的引用才能获得对RadGrid的引用。试着这样做:

var dataItems = 
$find('<%=RadGrid_IDPicker.ClientID%>').get_masterTableView().get_dataItems();

答案 2 :(得分:0)

我同意Icarus - 我认为你不需要获得对PanelBar的引用来访问RadGrid。如果您需要访问该链接按钮,则可以循环访问您获得的dataItems。您可以尝试执行以下操作:

var grid = $find("<%= RadGrid_IDPicker.ClientID %>");
var tbl = grid.get_masterTableView();
for (var i=0; i < tbl.get_dataItems().length; i++)
     var gridItemElem = tbl.get_dataItems()[i].findElement("LinkButton1");