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

Unable to create ListView programmatically

2 Answers 233 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Giovanni Pulvirenti
Top achievements
Rank 1
Giovanni Pulvirenti asked on 18 Feb 2010, 12:07 PM
Hello,
I'm really having too much troubles using RadListView. Now I'll try to briefly explain.
The project that I started to work on is a very specialized search engine using a complex data layer that can use one or more databases simultaneously. So I thought that was a good idea to use a RadListView with RadDataPager for a flexible paging.
Initially I was using the ASP.Net Controls version 2009.3.1103. Soon I realized that something was not going on as I expected: in fact, starting with no Data Source specified, after a postback initiated by another control, the data was not shown and the "no data template" was always presented. After a long search, finally I found a post in this forum that pointed me to this known bug.
Well, I did update the controls and the bug disappeared. But, unfortunately, now I'm stuck on the programmatic creation of the control. In fact I discovered that in design-time it is not possible to configure the RadListView via "smart tag option" since a valid data source is not specified.
A search engine cannot perform any query in a first page load, so I need to do all the data source job (dinamic query creation in response of the user parameter input) in a "if Page.IsPostBack then [...] End If" code block.
That's why I passed to the programmatic creation of the control.
Now, and this is the main problem to solve, it seems that there is no way to avoid this error message:
The RadListView control does not have an item placeholder specified.

For more clarity, this is the code-snippet in which I "try" to create the RadListView:

Private rlvResults As RadListView 
 
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init 
 
        Me.BuildListView() 
 
 
End Sub 
 
Protected Sub BuildListView() 
 
        Me.rlvResults = New RadListView() 
        With Me.rlvResults 
            .AllowCustomPaging = False 
            .AllowCustomSorting = False 
            .AlternatingItemTemplate = New GooWayTemplates.AlternatingItemTemplate() 
            .EditItemTemplate = New GooWayTemplates.EditItemTemplate() 
            .InsertItemTemplate = New GooWayTemplates.EditItemTemplate() 
            .ItemTemplate = New GooWayTemplates.ItemTemplate() 
            .EmptyDataTemplate = New GooWayTemplates.EmptyDataTemplate() 
            .LayoutTemplate = New GooWayTemplates.LayoutTemplate() 
            .SelectedItemTemplate = New GooWayTemplates.ItemTemplate() 
            .ItemPlaceholderID = "itemPlaceholder" 
            AddHandler .NeedDataSource, AddressOf rlvResults_NeedDataSource 
            .AllowPaging = True 
        End With 
 
        Me.placeHListView.Controls.Add(Me.rlvResults) 
 
 End Sub 

Where am I wrong?
This is a fundamental step in a big project and I'm really confused :-)

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 18 Feb 2010, 01:37 PM
Hello Giovanni,

The error you are getting does means that you should declare a control in your LayoutTemplate which to determine where the items (ItemTemplate, EditItemTemplate etc.) should be instantiated. Please refer to this live demo  for a sample of how to construct RadListView programmatically.

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.
0
Giovanni Pulvirenti
Top achievements
Rank 1
answered on 18 Feb 2010, 02:19 PM
Rosen,
Thank you very much,  this was very helpful.
Just a another point: my error was to use a "LiteralControl" as a "DIV tag builder" in this way:
   Public Class LayoutTemplate 
        Implements ITemplate 
 
        Public Sub New() 
        End Sub 
 
        Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn 
 
          Dim div As New LiteralControl("<div id=""itemPlaceholder""></div>") 
          container.Controls.Add(div) 
 
        End Sub 
    End Class 
 

Now, I think that LiteralControl class creates a span tag as container.
I changed the code in this way and all seems to be OK:
 Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn 
 
     Dim myDiv As New HtmlGenericControl("DIV") 
     With myDiv 
       .ID = "itemPlaceholder" 
       .InnerText = "myLayoutTemplate" 
     End With 
 
     container.Controls.Add(myDiv) 
 
 End Sub 

Hope this can be useful for some other.

Best regards,
Giovanni Pulvirenti
Tags
ListView
Asked by
Giovanni Pulvirenti
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Giovanni Pulvirenti
Top achievements
Rank 1
Share this question
or