RadListView ItemDataBound Firing Every Other Item

2 posts, 1 answers
  1. Seth
    Seth avatar
    66 posts
    Member since:
    Oct 2009

    Posted 02 Jun 2010 Link to this post

    I am having a problem with a RadListView.  I am binding the listview on the NeedDataSource event.  For some reason, the ItemDataBound event only fires every other item.  The listview is in an ItemTemplate of a RadPanelBar.  I am attaching these 2 events at runtime.

            <telerik:RadPanelItem Text="Contacts" Expanded="true" runat="server">  
                            <!-- Contact List --> 
                            <div id="zonePartyContacts" style="padding:5px">  
                                <telerik:RadListView ID="rlvContacts" runat="server" ClientDataKeyNames="NameAddrCode" DataKeyNames="NameAddrCode" AllowPaging="true" > 
                                            <table cellpadding="0" cellspacing="0" style="padding-top:10px; padding-bottom:5px">  
                                                <tr valign="top">  
                                                    <td id="itemPlaceholder" runat="server">  
                                            <telerik:RadDataPager ID="rdpContacts" runat="server" PageSize="3">  
                                                    <telerik:RadDataPagerButtonField FieldType="Numeric" /> 
                                        <td style="padding-right:10px;">  
                                            <asp:Label ID="lblContact" runat="server" Text='<%# Eval("Name") %>' CssClass="contactName"></asp:Label><br /> 
                                            <div id="zoneTitle" runat="server">  
                                                <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label><br /> 
                                            <div id="zonePhone" runat="server">  
                                                <asp:Image ID="imgPhone" runat="server" ImageUrl="~/Images/miniPhone.gif" ImageAlign="Middle" AlternateText="Phone Number" ToolTip="Phone Number" />&nbsp;<asp:Label ID="lblPhoneNumber" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>&nbsp;<asp:Label ID="lblExtension" runat="server" Text='<%# Eval("PhoneExtension") %>' /><br /> 
                                            <div id="zoneFax" runat="server">  
                                                <asp:Image ID="imgFax" runat="server" ImageUrl="~/Images/miniFax.gif" ImageAlign="Middle" AlternateText="Fax Number" ToolTip="Fax Number" />&nbsp;<asp:Label ID="lblFaxNumber" runat="server" Text='<%# Eval("Fax") %>'></asp:Label><br /> 
                                            <div id="zoneEmail" runat="server">  
                                                <asp:Image ID="imgEmail" runat="server" ImageUrl="~/Images/miniEmail.gif" ImageAlign="Middle" AlternateText="Email Address" ToolTip="Email Address" />&nbsp;<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("EmailAddress") %>'></asp:Label><br /> 
                                            <asp:HyperLink ID="hlNotes" runat="server" Text="Notes" NavigateUrl="#" Visible="false"></asp:HyperLink> 
                                            <telerik:RadToolTip ID="rttNotes" runat="server" RelativeTo="Element" TargetControlID="hlNotes"></telerik:RadToolTip> 

    ' PageLoad  
            rlvContacts = oPanelItemContacts.FindControl("rlvContacts")  
            AddHandler rlvContacts.NeedDataSource, AddressOf rlvContacts_NeedDataSource  
            AddHandler rlvContacts.ItemDataBound, AddressOf rlvContacts_ItemDataBound  
    ' NeedDataSource  
            Dim oParams As New NameValueCollection  
            oParams.Add("ParamNameAddrCode", _PartyCode)  
            Dim oResponse As wsProcedureManagement.procedureResponseClass = RunProcedure("GetNameAndAddressContacts", oParams)  
            rlvContacts.DataSource = oResponse.DataTableResult  
    ' ItemDataBound  
            If e.Item.ItemType = RadListViewItemType.DataItem Then 
                Dim oDataItem As RadListViewDataItem = CType(e.Item, RadListViewDataItem)  
                Dim oZone As HtmlGenericControl  
                ' Show or Hide title if it is available  
                oZone = e.Item.FindControl("zoneTitle")  
                oZone.Visible = oDataItem.DataItem("Title").ToString.Trim.Length > 0  
                ' Show or Hide phone if it is available  
                oZone = e.Item.FindControl("zonePhone")  
                oZone.Visible = oDataItem.DataItem("Phone").ToString.Trim.Length > 0 AndAlso oDataItem.DataItem("Phone").ToString.Trim <> "0" 
                ' Show or Hide fax if it is available  
                oZone = e.Item.FindControl("zoneFax")  
                oZone.Visible = oDataItem.DataItem("Fax").ToString.Trim.Length > 0 AndAlso oDataItem.DataItem("Fax").ToString.Trim <> "0" 
                ' Show or Hide email if it is available  
                oZone = e.Item.FindControl("zoneEmail")  
                oZone.Visible = oDataItem.DataItem("EmailAddress").ToString.Trim.Length > 0  
                ' Show or Hide notes if they are available  
                Dim oNotesLink As HyperLink = e.Item.FindControl("hlNotes")  
                oNotesLink.Visible = oDataItem.DataItem("Notes").ToString.Trim.Length > 0 Or oDataItem.DataItem("NotesLine2").ToString.Trim.Length > 0  
                If oNotesLink.Visible Then 
                    Dim oPopup As RadToolTip = e.Item.FindControl("rttNotes")  
                    If oDataItem.DataItem("Notes").ToString.Trim.Length > 0 Then 
                        oPopup.Text = oDataItem.DataItem("Notes").ToString  
                    End If 
                    If oDataItem.DataItem("NotesLine2").ToString.Trim.Length > 0 Then 
                        If oPopup.Text.Length > 0 Then 
                            oPopup.Text &= "<br />" 
                        End If 
                        oPopup.Text &= oDataItem.DataItem("NotesLine2").ToString()  
                    End If 
                End If 
            End If 
  2. Answer
    Rosen avatar
    3247 posts

    Posted 02 Jun 2010 Link to this post


    You are missing check if item's type is RadListViewItemType.AlternatingItem too in the ItemDataBound's if statement.

    If e.Item.ItemType = RadListViewItemType.DataItem Or e.Item.ItemType = RadListViewItemType.AlternatingItem Then

    All the best,
    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