RadListViewDataItem Retrieval

4 posts, 0 answers
  1. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 19 Nov 2009 Link to this post

    I'm using the RadListView in my project which is setup like so:
    <telerik:RadListView ID="lvCalendars" runat="server" AllowPaging="True" DataKeyNames="Listing_ID" 
                DataSourceID="dsListing" OnItemDataBound="lvCalendars_ItemDataBound"
                <LayoutTemplate> 
                    <telerik:RadDataPager ID="dpTopPager" runat="server" PagedControlID="lvCalendars" 
                        PageSize="7" Skin="Office2007"
                        <Fields> 
                            <telerik:RadDataPagerButtonField FieldType="Numeric" PageButtonCount="10" /> 
                        </Fields> 
                    </telerik:RadDataPager> 
                    <table cellpadding="0" cellspacing="0" width="100%" class="bgStandardMedium"
                        <tr id="itemPlaceholder" runat="server"
                        </tr> 
                    </table> 
                    <telerik:RadDataPager ID="dpBottomPager" runat="server" PagedControlID="lvCalendars" 
                        PageSize="7" Skin="Office2007"
                        <Fields> 
                            <telerik:RadDataPagerButtonField FieldType="Numeric" PageButtonCount="10" /> 
                        </Fields> 
                    </telerik:RadDataPager> 
                </LayoutTemplate> 
                <ItemTemplate> 
                    <tr> 
                        <td class="bgStandardDark propertySection"
                            <asp:Image ID="imgProperty" runat="server" Width="130px" Height="90px" AlternateText='<%#Eval("Name") %>' 
                                ToolTip='<%#Eval("Name") %>' /> 
                            <span class="propertyName"
                                <%#DataBinder.Eval(Container, "DataItem.Name").ToString() %> 
                            </span> 
                            <asp:HyperLink ID="lnkBookProperty" runat="server" CssClass="buttonStandard" Text="<span>Book Property</span>" 
                                Width="170px"></asp:HyperLink> 
                            <br /> 
                            <br /> 
                            <asp:LinkButton ID="lnkPrintCalendar" runat="server" CssClass="buttonStandard" Width="170px" 
                                Text="<span>Print Reservation List</span>"></asp:LinkButton> 
                        </td> 
                        <td class="calendarSection"
                            <telerik:RadAjaxPanel ID="apBookingCalendar" runat="server" LoadingPanelID="LoadingPanel1"
                                <telerik:RadCalendar ID="calBooking" runat="server" MultiViewColumns="4" MultiViewRows="1" 
                                    EnableMultiSelect="false" ShowRowHeaders="False" ShowOtherMonthsDays="False" 
                                    AutoPostBack="True" CssClass="bookingCalendar" OnDefaultViewChanged="calBooking_DefaultViewChanged"
                                    <CalendarTableStyle Width="175px" Height="196px" /> 
                                </telerik:RadCalendar> 
                                <div class="button-row" style="text-align: center;"
                                    <asp:LinkButton ID="lnkbtnViewFullYear" runat="server" CssClass="buttonStandard" 
                                        Text="<span>View Full Year</span>" Width="150px" /> 
                                </div> 
                            </telerik:RadAjaxPanel> 
                            </li> 
                        </td> 
                </ItemTemplate> 
            </telerik:RadListView> 

    Now in my calendar's OnDefaultViewChanged event I attempt to retrieve the RadListViewDataItem it's contained in like so:

    protected void calBooking_DefaultViewChanged(Object sender, Telerik.Web.UI.Calendar.DefaultViewChangedEventArgs e) 
        { 
            try 
            { 
                // get calendar 
                RadCalendar calBooking = (RadCalendar)sender; 
                // get RadListViewDataItem 
                RadListViewDataItem dtItem = (RadListViewDataItem)calBooking.Parent.Parent; 
     
                // hold Sub Listing 
                SubListing subListing = new SubListing(); 
     
                // hold Listing 
                Listing listing; 
     
                // check if data item is a listing 
                if (dtItem.DataItem is Listing) 
                { 
                    // get listing 
                    listing = (Listing)dtItem.DataItem; 
                } 
                else 
                { 
                    // get sub listing 
                    subListing = (SubListing)dtItem.DataItem; 
                    // get listing 
                    listing = subListing.Listing; 
                } 
     
                //...calendar setup code follows
     
            } 
            catch (Exception ex) 
            { 
            } 
        } 

    Now apparently DataItem does not exist, I get a null value. I was able to retrieve the DataItem object in the ItemDataBound event of the RadListView control but not in the calendar event. 

    Is there a reason for this or is it some bug in the RadListView control?

    I am using the latest version of the controls 3.1105 (.NET 3.5).
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 20 Nov 2009 Link to this post

    Hi,

    As you may know when using DataBoundControls, Item's DataItem property is only populated when control is created from the accosted datasource and not when the control is recreated from its ViewState. Therefore if you want to use some part of the object associated with an Item of ListView control, on an event which will not cause the control to be repopulated, you should use some other approach get the object. For example you can use DataKeyNames. This way you may retrieve the full object by its key or use the value directly if it is sufficient for the scenario in question.

    Kind regards,
    Rosen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. cute gal
    cute gal avatar
    5 posts
    Member since:
    Mar 2010

    Posted 26 Mar 2010 Link to this post

    hi.. i want to print contents populated within radlistview
    i wonder to get data and activate printer settings on the clink event of linkbutton..

     <asp:Panel ID="ListViewPanel1" runat="server"
                        <telerik:RadListView ID="RadListView1" runat="server" DataKeyNames="PrivacyId" DataSourceID="source1" 
                            ItemPlaceholderID="ListViewContainer" RegisterWithScriptManager="true" allowsorting="true" 
                            AllowPaging="True" Font-Names="Arial"
                            <LayoutTemplate> 
                                <asp:PlaceHolder ID="ListViewContainer" runat="server" /> 
                            </LayoutTemplate> 
                            <ItemTemplate> 
                                <table> 
                                    <tr> 
                                        <td> 
                                            &nbsp; 
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            <%#Eval("Heading")%> 
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            &nbsp; 
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            <%#Eval("Description")%> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </ItemTemplate> 
                        </telerik:RadListView> 
                    </asp:Panel> 
     
    <asp:SqlDataSource ID="source1" runat="server" ConnectionString="<%$ ConnectionStrings:helpConnectionString %>" 
                        SelectCommand="SELECT * FROM [Privacy]"></asp:SqlDataSource> 
     
    <asp:LinkButton ID="lnkPrint" runat="server" >Print this Page</asp:LinkButton> 

  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 29 Mar 2010 Link to this post

    Hi,

    There is no such functionality built into the RadListView. However you may look at this code library which demonstrates how to achieve similar thing with RadGrid and adapt the code to fit your case.

    All the best,
    Rosen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top