开发者

ASP.Net Data Bind Environmental Issue

Using a repeater to data bind a common control we are having issues where the data bound control is not being bound in different environments.

The old works on my machine issue.

We have the below repeater:

<web:Repeater ID="rptVehicles" runat="server" DataType="Entities.VehicleSummary" OnItemDataBound="rptItemList_OnItemDataBound">
<ItemTemplate>
    <div style="display:none">  
        <p>Container Item = <%# (Container.DataItem == null) ? "null" : "not null" %>&l开发者_JAVA技巧t;/p>
        <p>Container Item Id = <%# (Container.DataItem.ID == null) ? "null" : "not null" %></p>
        <p>Container Item Id = <%# Container.DataItem.ID %></p>
    </div>
    <common:VehicleItem runat="server" ID="itmVehicle" DataSource="<%# Container.DataItem %>" ImageDefinition="<%# this.ImageDefinition %>"  />
</ItemTemplate>
</web:Repeater>

And the contents of the Vehicle Item user control:

<div class="m-vitem">
<div style="display:none">
    <p>DataSourceSet = <%# this.DataSourceSet %></p>
    <p>Item DataSource = <%# (this.DataSource == null)? "null" : "not null" %></p>
</div>

On local the data source setter gets called passing in the Vehicle Summary entity.

DataSourceSet property is set to true in the DataSource property setter, on local its output is true on testing its false.

We are using different .Net versions on local and testing environments, does anyone know if there are any difference in the data bind handling between versions and what can be done, or am I barking up the wrong tree?

LOCAL - Microsoft .NET Framework Version:2.0.50727.4961; ASP.NET Version:2.0.50727.4955 TESTING- Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082


It looks like the code in your base property that was performing the set up was not being called since the overriding property on your vehicles entity. Marking a base property as virtual only makes the compiler choose which version of the property it needs to use at run-time. It does not mean that the base property setter's code is run before/after the sub class` property setter.

Also, it doesn't make sense to actually do any 'set up' in a property, you'd ideally want to move that to the base constructor, where it would be executed if you call your base constructor from your object's constructor. Alternatively but less ideally, you could perform the set up in your overriding property as well.

Moving the set up code to OnDataBinding works for you since the DataBind event is fired automatically whenever you set the DataSource property of the repeater.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜