Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

SPContext item changing inadvertently (visual webpart)

$
0
0

(Using .Net to develop SP2010 visual web parts on a custom list)

I have an unusual one here. I have created a web part that is used on the DispForm of a custom list. I include on the web part a gridview of “related” items from the same list.

I don’t think it makes much difference, but I mocked up the layout below. What is happening: if my webpart is not on the page, the page works as expected. But once I drop my webpart on the page, the data that shows in the OOTB web part is actually data from item 1 of my gridview.

So let’s say the displayed item is item 20. The gridview shows “related” items 45, 63 and 78. When I go to my default view on my site and open item 20, the OOTB web part (left-hand web part zone) shows the data from item 45.

The behavior is consistent. I can make a change to cause item 45 to no longer be included in the related items, so that the related items only include 63 and 78. When I do that, item 63 is what shows in the OOTB web part (again, rather than the selected item 20).

OOTB Display web part

Label : value

Label : value

(standard sharepoint page layout, in other words)

My custom web part

<some field values from the current item are listed here>

<

Gridview is here:

Item 1

Item 2

Item 3

>

The only idea that I could come up with was that maybe the RowDataBound logic was somehow having a side effect of changing the spcontext. I commented out the lines in the RowDataBound event that create the hyperlinked column, but the problem still happens.

Is there a common mistake that I might be making here that might explain this? Debugging hasn’t told me anything yet, but maybe there is a way to step through something that I am stepping over by default that would help me to see when this switcheroo is happening. ??

Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>