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

ListView Binding Twice? Strange Behaviour

1 Answer 73 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Richard Weeks
Top achievements
Rank 2
Richard Weeks asked on 02 Jun 2010, 01:12 AM
I have a very simple RadListView populated from a DataSet:

Data:

HeadingOne  HeadingTwo  DataValue  
First       Second      Data Value  
First       Second      Data Value  
First       Third       Data Value  
First       Third       Data Value  
First       Third       Data Value 

ListView:

<telerik:RadListView   
    ID="MyListView"   
    runat="server"   
    OnNeedDataSource="MyListView_OnNeedDataSource">  
 
    <ItemTemplate> 
              
        <%# InsertHeadingOne() %> 
 
        <%# InsertHeadingTwo() %> 
 
        <p><%# Eval("DataValue") %></p>  
 
    </ItemTemplate> 
 
</telerik:RadListView>  

I thought I was being very cunning in my grouping efforts. The two method calls above are:

string lastHeadingOne = string.Empty;  
string lastHeadingTwo = string.Empty;  
 
protected string InsertHeadingOne()  
{  
    string currentHeadingOne = Eval("HeadingOne").ToString();  
 
    if (currentHeadingOne.Length == 0)  
    {  
        currentHeadingOne = string.Empty;  
    }  
 
    if (this.lastHeadingOne != currentHeadingOne)  
    {  
        this.lastHeadingOne = currentHeadingOne;  
 
        return string.Format("<h1>{0}</h1>", currentHeadingOne);  
    }  
    else 
    {  
        return string.Empty;  
    }  
}  
 
protected string InsertHeadingTwo()  
{  
    string currentHeadingTwo = Eval("HeadingTwo").ToString();  
 
    if (currentHeadingTwo.Length == 0)  
    {  
        currentHeadingTwo = string.Empty;  
    }  
 
    if (this.lastHeadingTwo != currentHeadingTwo)  
    {  
        this.lastHeadingTwo = currentHeadingTwo;  
 
        return string.Format("<h2>{0}</h2>", currentHeadingTwo);  
    }  
    else 
    {  
        return string.Empty;  
    }  

But when I run the page, I get this output:

Second  
Data Value  
Data Value  
 
Third  
Data Value  
Data Value  
Data Value 

What I should be getting is this?:

First  
 
Second 
Data Value  
Data Value  
 
Third 
Data Value  
Data Value  
Data Value 

When I step through in debug I see the correct strings being returned but for the 5 rows in the DataSet, there are 10 calls to each method! It seems the second pass wipes the values from the first - but then, if that is the case, how did the Heading Twos get returned? I'm confused :)

Very strange. It works really well for the level 2 headings but not at all from the level one. Can anyone help?

Many thanks in advance,
Richard


1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 02 Jun 2010, 07:06 AM
Hi Richard,

Are you using latest version Q1 2010 SP2 of Telerik.Web.UI assemblies, as our developers have already addressed similar problem? If not, please try the latest service pack and see if there is change in the observed behavior.

Sincerely yours,
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
Richard Weeks
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or