accessing radgrid from webpart

6 posts, 0 answers
  1. Nate
    Nate avatar
    4 posts
    Member since:
    Aug 2010

    Posted 01 Jun 2011 Link to this post

    I'm trying to access data from a radgrid from a sharepoint webpart on the same page as the radgrid.  When I execute the GridDataItem Item line, it throws a null reference exception and says "Object is not set to instance of an object".  Why isn't it finding the control?


      
    using (SPSite external = new SPSite(SPContext.Current.Web.Url))
        {
            using(SPWeb web = external.OpenWeb())
            {
                  
                RadGrid ProjectGrid = (RadGrid)FindControl("rgViewPDS");
                GridDataItem item = ProjectGrid.Items[0];
                this.PP = item["PP"].Text;
                this.PED = item["PED"].Text;
            }
        }
    });
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 03 Jun 2011 Link to this post

    Hi Nate,

    Could you please elaborate a bit more on your application. Does the RadGrid control added to a UserControl into your WebPart. If yes note that you need to access the mentioned UserControl before access the RadGrid. Some more information on your configuration and the exact steps you are using for achieving the required functionality will help us to further investigate the issue and provide proper solution.

    Kind regards,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.


  3. Nate
    Nate avatar
    4 posts
    Member since:
    Aug 2010

    Posted 03 Jun 2011 Link to this post

    I have two web parts on the page.  One is a custom page viewer and the other is the RadGrid.  The URL for the page viewer requires data from the RadGrid as query string parameters.  Within the page viewer code, I'm trying to do a FindControl for the RadGrid, access the first row of data, and obtain the PP and PED values.  When I do a FindControl, it returns null. 

    This is the configuration for the RadGrid:

    <telerik:RadGrid 
         ID="rgViewPDS" 
         runat="server" 
         OnNeedDataSource="rgViewPDS_NeedDataSource"
         AllowPaging="True"
         PageSize="20"  
         AllowSorting="True"  
         ShowGroupPanel="True"
         AutoGenerateColumns="False" 
         EnableEmbeddedSkins="false" 
         GridLines="None" 
         Skin="Tkn2_RadSkins"       
         OnItemCommand="rgviewPDS_ItemCommand"
         ShowStatusBar="True" >
           
         <MasterTableView    
             ClientDataKeyNames="ProjectSiteUrl" 
             Width="100%" 
             AllowAutomaticUpdates="false" 
             CommandItemDisplay="Top" 
             AllowAutomaticDeletes="False" 
             AllowAutomaticInserts="False" 
             AllowFilteringByColumn="True"
             EnableNoRecordsTemplate="true"
             ShowHeadersWhenNoRecords="true" 
             AllowMultiColumnSorting="True" AllowPaging="True">          
                  <Columns>                 
                     <telerik:GridButtonColumn Text="Create" ItemStyle-CssClass="" ButtonType="PushButton" UniqueName="TransmittalURL" HeaderText="Create Transmittal" CommandName="CreateTransmittal" />        
                     <telerik:GridBoundColumn DataField="ProjectName" UniqueName="ProjectName" HeaderText="Project Name" /> 
                     <telerik:GridBoundColumn DataField="ProjectNumber" UniqueName="ProjectNumber" HeaderText="Project Number" />                      
                     <telerik:GridBoundColumn DataField="SiteURL" UniqueName="SiteURL" HeaderText="Project Site" />      
                     <telerik:GridBoundColumn HeaderText="Prolog ID" UniqueName="PP" DataField="PP" />
                     <telerik:GridBoundColumn HeaderText="Prolog Portfolio" UniqueName="PED" DataField="PED" />
                  </Columns>
                  <CommandItemSettings />
                  <CommandItemTemplate >
                     <asp:Panel runat="server" ID="CommandItemPanel" Style="padding: 4px; line-height: 24px; vertical-align: middle;" Width="100%" Wrap="False">
                                 <div style="float: left">
                                     <span style="margin-right: 3px;"> </span>                                    
                                 </div>                        
                                 <div style="float: right; margin-right: 3px">
                                       
                                 </div>                             
                                 <div style="float: right">
                                     <span style="margin-right: 3px;"><asp:LinkButton id="LinkButton2"  runat="server" OnClick="RefreshMe" Text="Refresh Tasks list">
                                     <img style="border:0px;vertical-align:middle;" alt="" 
                                     src="/_layouts/Images/Tkn/Refresh.gif" /><span style="margin-left: 3px;">Refresh</span>
                                     </asp:LinkButton></span>                                    
                                 </div>
                                           
                     </asp:Panel>
                 </CommandItemTemplate>
                 <NoRecordsTemplate>There is no data to show in this list.</NoRecordsTemplate>
                   
                 <PagerTemplate>
                     <asp:Panel ID="PagerPanel" Style="padding: 6px; line-height: 24px" runat="server">
                         <div style="float: left">
                             <span style="margin-right: 3px;"> </span>
                               
                         </div>
                         <div style="margin: 0px; float: right;">
                             Displaying page
                             <%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>
                             of
                             <%# DataBinder.Eval(Container, "Paging.PageCount")%>
                             , items
                             <%# (int)DataBinder.Eval(Container, "Paging.FirstIndexInPage") + 1 %>
                             to
                             <%# (int)DataBinder.Eval(Container, "Paging.LastIndexInPage") + 1 %>
                             of
                             <%# DataBinder.Eval(Container, "Paging.DataSourceCount")%>
                         </div>
                         <div style="margin: 0px; padding: 0px; float: left; margin-right: 10px; white-space: nowrap;">
                             <asp:LinkButton ID="Button1" runat="server" OnClientClick="changePagePDS('first'); return false;"
                             CommandName="Page" CommandArgument="First" Text="<<"><img style="border:0px;vertical-align:middle;" alt="Edit selected Task" 
                                                                     src="/_layouts/Images/Tkn/PagingFirst.gif" /></asp:LinkButton>
                             <asp:LinkButton ID="Button2" runat="server" OnClientClick="changePagePDS('prev'); return false;"
                             CommandName="Page" CommandArgument="Prev" Text="<" ><img style="border:0px;vertical-align:middle;" alt="Edit selected Task" 
                                         src="/_layouts/Images/Tkn/PagingPrev.gif" /></asp:LinkButton>
                             <span style="vertical-align: middle;">Page:</span>
                             <telerik:RadNumericTextBox ID="RadNumericTextBoxPDS" Width="25px" Value='<%# (int)DataBinder.Eval(Container, "Paging.CurrentPageIndex") + 1 %>'
                                 runat="server">
                                 <ClientEvents OnValueChanged="RadNumericTextBoxPDS_ValueChanged" />
                                 <NumberFormat DecimalDigits="0" />
                             </telerik:RadNumericTextBox>
                             <span style="vertical-align: middle;">of
                                 <%# DataBinder.Eval(Container, "Paging.PageCount")%>
                             </span>
                             <asp:LinkButton ID="Button3" runat="server" OnClientClick="changePagePDS('next'); return false;"
                             CommandName="Page" CommandArgument="Next" Text=">" ><img style="border:0px;vertical-align:middle;" alt="Edit selected Task" 
                                                                     src="/_layouts/Images/Tkn/PagingNext.gif" /></asp:LinkButton>
                             <asp:LinkButton ID="Button4" runat="server" OnClientClick="changePagePDS('last'); return false;"
                             CommandName="Page" CommandArgument="Last" Text=">>" ><img style="border:0px;vertical-align:middle;" alt="Edit selected Task" 
                                         src="/_layouts/Images/Tkn/PagingLast.gif" /></asp:LinkButton>
                         </div>
                         <asp:Panel runat="server" ID="NumericPagerPlaceHolder" />
                     </asp:Panel>
                 </PagerTemplate>
             </MasterTableView>        
             <ClientSettings EnableRowHoverStyle="true"
                             EnablePostBackOnRowClick="true"
                             ReorderColumnsOnClient="True" 
                             AllowDragToGroup="True" 
                             AllowColumnsReorder="True">
                             <Selecting  AllowRowSelect="True"></Selecting>
                             <Resizing   AllowRowResize="True" 
                             EnableRealTimeResize="True" 
                             ResizeGridOnColumnResize="True"
                             AllowColumnResize="True"></Resizing>
             </ClientSettings>        
             <FilterMenu />   
         </telerik:RadGrid>


  4. Nate
    Nate avatar
    4 posts
    Member since:
    Aug 2010

    Posted 06 Jun 2011 Link to this post

    Does anyone know how to fix this?
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 07 Jun 2011 Link to this post

    Hello Nate,

    Please ensure that you are calling FindControl for the whole UserControl in which the RadGrid is added before calling FindControl() for the RadGrid itself. You need to find the parent UserControl before accessing its internal controls.

    Best wishes,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  6. Nate
    Nate avatar
    4 posts
    Member since:
    Aug 2010

    Posted 07 Jun 2011 Link to this post

    Thanks!  That worked perfectly!
Back to Top