This is a migrated thread and some comments may be shown as answers.

RadListView ItemDataBound Firing Every Other Item

1 Answer 483 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 02 Jun 2010, 02:35 PM
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">  
            <Items> 
                <telerik:RadPanelItem> 
                    <ItemTemplate> 
                        <!-- Contact List --> 
                        <div id="zonePartyContacts" style="padding:5px">  
                            <telerik:RadListView ID="rlvContacts" runat="server" ClientDataKeyNames="NameAddrCode" DataKeyNames="NameAddrCode" AllowPaging="true" > 
                                <LayoutTemplate> 
                                    <div> 
                                        <table cellpadding="0" cellspacing="0" style="padding-top:10px; padding-bottom:5px">  
                                            <tr valign="top">  
                                                <td id="itemPlaceholder" runat="server">  
                                                </td> 
                                            </tr> 
                                        </table> 
                                        <telerik:RadDataPager ID="rdpContacts" runat="server" PageSize="3">  
                                            <Fields> 
                                                <telerik:RadDataPagerButtonField FieldType="Numeric" /> 
                                            </Fields> 
                                        </telerik:RadDataPager> 
                                    </div> 
                                </LayoutTemplate> 
                                <ItemTemplate> 
                                    <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> 
                                        <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> 
                                        <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> 
                                        <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 /> 
                                        </div> 
                                        <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> 
                                    </td> 
                                </ItemTemplate> 
                            </telerik:RadListView>   
                        </div> 
                    </ItemTemplate> 
                </telerik:RadPanelItem> 
            </Items> 
        </telerik:RadPanelItem> 
 

' 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 
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 02 Jun 2010, 03:49 PM
Seth,

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,
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.
Tags
ListView
Asked by
Seth
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or