开发者

Asp.Net ListView's Items property is always empty

Good day

I have a user control that contains a ListView which is being used to display tabs.

I am databinding the ListView and on the OnItemDataBound event adding the tab elements. However the Items property never contains anything and is always empty (on PostBack and on ItemDataBound).

Markup:

<asp:ListView ID="SaleTabsListView" runat="server" OnItemDataBound="SaleTabsListView_OnItemDataBound" ItemPlaceholderID="SaleTabsPlaceHolder" EnableViewState="true">
    <LayoutTemplate>
        <div class="tabs">
            <asp:PlaceHolder runat="server" ID="SaleTabsPlaceHolder" />
        </div>
    </LayoutTemplate>
    <ItemTemplate>
        <asp:PlaceHolder runat="server" ID="ItemPlaceHolder" />
    </ItemTemplate>
</asp:ListView>

Code behind:

protected void SaleTabsListView_OnItemDataBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            var saleTab = ((ListViewDataItem)e.Item).DataItem as SalesTab;
            if (saleTab != null)
            {
                var placeHolder = e.Item.FindControl("ItemPlaceHolder") as PlaceHolder;
                var htmlAnchor = new HtmlAnchor();
                htmlAnchor.Attributes.Add("id", saleTab.Id);
                htmlAnchor.Attributes.Add("class", saleTab.IsCurrent ? currentTabClass : string.Empty);

                var emptyLabel = new Label();

                var label = new Label {Text = saleTab.Title};
                label.Attributes.Add("id", saleTab.Id + "Label");
                label.Attributes.Add("class", saleTab.IsComplete ? completeClass : incompleteClass);

  开发者_开发问答              emptyLabel.Controls.Add(label);
                htmlAnchor.Controls.Add(emptyLabel);
                placeHolder.Controls.Add(htmlAnchor);
            }
        }
    }

So my question is: is the binding I'm doing somehow screwing with the Items property?

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜