ListView Binding Twice? Strange Behaviour

2 posts, 0 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 01 Jun 2010 Link to this post

    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


  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 02 Jun 2010 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top