Problem with RadList view and Embedded Grid

6 posts, 0 answers
  1. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 21 Jan 2011 Link to this post

    I am using the Telerik.Web.UI version 2010.3.1317.40
    Visual Studio 2010 premium.  .NET 4.0

    I have a simple grid, embedded in a simple List View.

    The data source for the list view is a Class Object.

    When I get to the point that I am trying to get the list views key data value of customer number, it fails to set the parameter.

    Let me post my code:

    <%@ Page Language="c#" CodeBehind="AddressBook.aspx.cs" AutoEventWireup="True"
        EnableViewState="true" Inherits="JDE.Reporting.AddressBook" MasterPageFile="~/MenuMaster.Master" %>
      
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <asp:Content ID="WorkTracker" runat="server" ContentPlaceHolderID="MainPage">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
        </telerik:RadStyleSheetManager>
        <h2>
            <asp:Label ID="lblReportHeader" runat="server"></asp:Label></h2>
          <p>
                
              <asp:Label ID="Label9" runat="server" Font-Bold="True" Font-Size="Large" 
                  ForeColor="#3399FF"></asp:Label>
              <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
      
                
                <telerik:RadSkinManager ID="RadSkinManager1" Runat="server" Skin="Windows7">
                </telerik:RadSkinManager>
      
        </p>
              <telerik:RadListView ID="RLV_Address" runat="server" 
                    DataKeyNames="CustomerNumber"
                    ItemPlaceholderID="Addresses"
                    onneeddatasource = "RLV_Address_NeedDataSource">
                      <LayoutTemplate>
                        <fieldset>
                            <legend>
                            Address
                            </legend>
                            <asp:PlaceHolder ID="Addresses" runat="server" />
                        </fieldset>
                      </LayoutTemplate>
      
                      <ItemTemplate>
                        <legend> <p> Customer Number: <%#Eval("CustomerNumber")%> </p><p>Customer Name : <%# Eval("CustomerName") %> </p> <p>Customer Type : <%# Eval("CustomerType") %> </p></legend>
                          
                        <telerik:RadGrid ID="rgContacts" runat="server" AllowFilteringByColumn="False"
                                                AllowPaging="False" AllowSorting="false" ClientSettings-AllowColumnHide="false"
                                                AutoGenerateColumns="False" ShowGroupPanel="false" ShowFooter="true" EnableHeaderContextMenu="false"
                                               OnNeedDataSource="RG_Contacts_NeedDataSource">
                                                <MasterTableView CommandItemDisplay="None">
                                                    <RowIndicatorColumn>
                                                        <HeaderStyle Width="20px"></HeaderStyle>
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn>
                                                        <HeaderStyle Width="20px"></HeaderStyle>
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        <telerik:GridBoundColumn DataField="CustomerNumber" HeaderText="CustomerNumber" UniqueName="CustomerNumber">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="FullName" HeaderText="FullName" UniqueName="FullName">
                                                        </telerik:GridBoundColumn>
                                                    </Columns>
                                                    <NoRecordsTemplate>
                                                        <asp:Label ID="lblNoTotalsRecords" runat="server" CssClass="LabelBold" Text="No records for the filtering selections you have chosen."></asp:Label>
                                                    </NoRecordsTemplate>
                                                </MasterTableView>
                                            </telerik:RadGrid>            
                       </ItemTemplate>
      
                    <ItemSeparatorTemplate>
                        <span style="color: Blue; font-weight: bold;">   ::   </span>
                    </ItemSeparatorTemplate
      
               </telerik:RadListView>
      
              <asp:PlaceHolder ID="Addresses" runat="server"></asp:PlaceHolder>
          
      
    </asp:Content>
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
      
    using System.Net.Mail;
    using System.Collections.Generic;
    using System.Text;
      
    using JDEReporting.Code;
    using Marlin.Utilities;
      
    using System.Reflection;
      
    namespace JDE.Reporting
    {
        // Remember to change the name of the class here to be the same value as is used
        // in the inherit on the .aspx page.
        public partial class AddressBook : System.Web.UI.Page
        {
    //      protected System.Web.UI.WebControls.Label lblTable;
            Marlin.JDE.AddressBook.cAddressBooks mcAddressBooks;
      
            protected void Page_Load(object sender, System.EventArgs e)
            {
      
                this.MaintainScrollPositionOnPostBack = true;
      
                if (!IsPostBack)
                {
                    // Get the name of the routine we are currently running.
                    MethodBase lmth = MethodBase.GetCurrentMethod();
                    string lsRoutineName = lmth.DeclaringType + "." + lmth.Name;
      
                    string lsReportName = MiscDBFuncs.GetReportTitle(Request.Url.Segments[Request.Url.Segments.Length - 1]);
                    lblReportHeader.Text = lsReportName;
                    Page.Title = lsReportName;
      
                    mcAddressBooks = new Marlin.JDE.AddressBook.cAddressBooks(345183, Session["UserName"].ToString().Trim());
                 }   
            }
      
            protected void RLV_Address_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
            {
                RLV_Address.DataSource = mcAddressBooks;
            }
      
            void RLV_Address_Item_ItemDataBound(object sender, RadListViewItemEventArgs e)
            {
                if (e.Item is RadListViewDataItem)
                {
                    var grid = (RadGrid)e.Item.FindControl("RG_Contacts");
                    grid.Rebind();
                }
            }
      
      
            protected void RG_Contacts_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                var parentItem = RLV_Address.NamingContainer as RadListViewDataItem;
      
                if (parentItem.DataItem == null)
                    return;
                  
                int intID = (int)parentItem.GetDataKeyValue("CustomerNumber");
      
                RadGrid rg_Contacts = (RadGrid)source;
                rg_Contacts.DataSource = mcAddressBooks[intID].AddressBookContacts;
            }
             


    The error occurs in the Need Data source of the grid.   When I try to set the parentiem, it is set to a value of null, or nothing.
    I wind up with an error at the if(parentItem.DataItem == null) section of the code telling me that parentiem is null. 

    So, the code works for everything but this part, if I had code the intID to 0, and simply set the rg_Contacts.DataSource to mcAddressBooks[0].AddressBookContacts  I get it to display, but simply with the 0 index of the class.

    I would appreciate any help.
  2. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 27 Jan 2011 Link to this post

    Hello Jack,

    Have you tried removing the Rebind() call for the grid from your ItemDataBound event of the listview? RadGrid should be able to fire its NeedDataSource event implicitly when it needs to bind.

    Best wishes,
    Tsvetina
    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. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 27 Jan 2011 Link to this post

    I tried that and still got the same error message when the RAD Grid Need Data Source event fired off, that parentiem is null. 
    Is there another way to get to the "ID" value in the Listview?
  5. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 27 Jan 2011 Link to this post

    The problem is definately here,

    var parentItem = RLV_Address.NamingContainer as RadListViewDataItem;

    It does not set the parentItem to anything.

    I can not figure out why.

  6. Tsvetina
    Admin
    Tsvetina avatar
    1876 posts

    Posted 31 Jan 2011 Link to this post

    Hi Jack,

    I answered your question in the support ticket that you sent to us but I am posting it here as well, so other people with similar problem can use it:

    The problem is that you are taking the NamingContainer of the RadListView, instead of the RadGrid object at the problemmatic place. The NamingContainer of the listview is the Page itself and it cannot be cast to RadListViewItem, therefore it is null. If you change this line:

    var parentItem = RadListView1.NamingContainer as RadListViewDataItem;
     to this:

    var parentItem = (source as RadGrid).NamingContainer as RadListViewDataItem;

     the exception goes away and the grids inside the listview get populated.

    In order to avoid duplicate posts, please, if you have any other questions, post them in the formal support ticket.

    Regards,
    Tsvetina
    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.
  7. Jack Voss
    Jack Voss avatar
    27 posts
    Member since:
    May 2010

    Posted 31 Jan 2011 Link to this post

    That worked well,

    Thank you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017