views:

116

answers:

1

I have what I think to be an odd problem with listview databinding.

I am calling a protected method on my code-behind called ItemHtml() - as seen below.

    <ItemTemplate>
        <div class="itemWrapper">
            <%# ItemHtml() %>
        </div>
    </ItemTemplate>

The method is defined as follows.

protected string ItemHtml()
{
    string itemHtml =
        StateHeaderIfNewState()
           + ActivityOwnerIfNew()
           + ActivityCategoryIfNew()
           + ActivityDescriptionHtml()
           + TaskDescriptionHtml()
           + RecordDetailsHtml();   
    Trace.Write("DEBUG", itemHtml);
    return itemHtml;
}

The trace shows an "itemHtml" like the following (I've removed the actual html from the code to ensure it's not just invalid html): Virginia, Activity Owner Name, Category, Activity, Task, Details

However, the page source is missing the first two values (begins with "Category").

Am I misunderstanding something about listview databinding? How could the trace have one value, but the source have another?

+2  A: 

Your "View Source" click is generating a new http request causing a new call to the server which now has a new response (presumably due to the logic implied by "IfNew"). In my opinion, it is not possible for your itemHtml variable to have the two different values you describe at the same time.

If I am correct, you should have multiple traces as a result of the multiple requests.

grenade
Ah, I didn't realize that was a new request, makes sense. You're correct, the ifnew logic causes that. My main concern of course is that the output on the page does not include the items that I would expect to see (Virginia, Activity Owner Name). I was just using view source to verify the output. Based on the trace values, I should be seeing the output on the page right? I'm not sure why it's not there.
Jeremy
I'd set a breakpoint in the first couple of methods to see whats going on in debug mode.
grenade
In looking at the trace closer (debugging didn't quite get me there because the first pass through was working as expected), each item was binding twice. Turns out I was explicitly calling listView.DataBind() - didn't realize just setting the DataSourceID would implicitly call DataBind(). Since it was called twice, the ifNew logic was evaluated as false the 2nd time.
Jeremy