我在 ASP .NET 2.0 应用程序中遇到问题。
我有一个 GridView 显示来自 ObjectDataSource 的数据(连接到连接到 TabledAdapter 的 BLL 类(使用乐观并发的类型化数据集)。
选择(显示数据)工作得很好,但是,当我更新一行时,GridView 确实将旧值传递给 ObjectDataSource。
<DataObjectMethod(DataObjectMethodType.Update, True)> _
Public Function UpdateOC(ByVal original_id As Integer, ByVal original_fotonummer As Integer, ByVal original_inhoud As String, ByVal original_postdatum As Date?, ByVal fotonummer As Integer, ByVal inhoud As String, ByVal postdatum As Date?) As Boolean
Dim tweets As TwitpicOC.TweetsDataTable = adapterOC.GetTweetById(original_id)
If tweets.Rows.Count = 0 Then Return False
Dim row As TwitpicOC.TweetsRow = tweets(0)
SmijtHetErIn(row, original_fotonummer, original_inhoud, original_postdatum)
row.AcceptChanges()
SmijtHetErIn(row, fotonummer, inhoud, postdatum)
Return adapterOC.Update(row) = 1
End Function
Public Sub SmijtHetErIn(ByVal row As TwitpicOC.TweetsRow, ByVal original_fotonummer As Integer, ByVal original_inhoud As String, ByVal original_postdatum As Date?)
With row
.fotonummer = original_fotonummer
If String.IsNullOrEmpty(original_inhoud) Then .SetinhoudNull() Else .inhoud = original_inhoud
If Not original_postdatum.HasValue Then .SetpostdatumNull() Else .postdatum = original_postdatum.Value
End With
End Sub
这是页面的一部分:
<div id='Overzicht' class='post'>
<div class='title'>
<h2>
<a href='javascript:;'>Tweetsoverzicht</a></h2>
<p>
Overzicht</p>
</div>
<div class='entry'>
<p>
<asp:ObjectDataSource ID="odsGebruiker" runat="server" OldValuesParameterFormatString=""
SelectMethod="GetAll" TypeName="TakeHomeWeb.BLL.GebruikersBLL"></asp:ObjectDataSource>
<asp:ObjectDataSource ID="odsFoto" runat="server" SelectMethod="GetFotosByGebruiker"
TypeName="TakeHomeWeb.BLL.FotosBLL">
<SelectParameters>
<asp:ControlParameter ControlID="ddlGebruiker" DefaultValue="0" Name="userid" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<form id="form1" runat="server">
<asp:Label runat="server" AssociatedControlID="ddlGebruiker">Gebruiker: </asp:Label>
<asp:DropDownList ID="ddlGebruiker" runat="server" AutoPostBack="True" DataSourceID="odsGebruiker"
DataTextField="naam" DataValueField="userid" AppendDataBoundItems="True">
<asp:ListItem Text="Kies een gebruiker" Value="-1" />
</asp:DropDownList>
<br />
<asp:Label runat="server" AssociatedControlID="ddlFoto">Foto: </asp:Label>
<asp:DropDownList ID="ddlFoto" runat="server" AutoPostBack="True" DataSourceID="odsFoto"
DataTextField="url" DataValueField="id" AppendDataBoundItems="True">
<asp:ListItem Value="-1">Kies een foto...</asp:ListItem>
</asp:DropDownList>
<br />
<div style="float: left">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="odsTweets">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="fotonummer" HeaderText="fotonummer" SortExpression="fotonummer" />
<asp:BoundField DataField="inhoud" HeaderText="inhoud" SortExpression="inhoud" />
<asp:BoundField DataField="postdatum" HeaderText="postdatum" SortExpression="postdatum" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsTweets" runat="server" ConflictDetection="CompareAllValues"
DeleteMethod="DeleteOC" OldValuesParameterFormatString="original_{0}" SelectMethod="GetTweetsByFotoId"
TypeName="TakeHomeWeb.BLL.TweetsOCBLL" UpdateMethod="UpdateOC">
<DeleteParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_fotonummer" Type="Int32" />
<asp:Parameter Name="original_inhoud" Type="String" />
<asp:Parameter Name="original_postdatum" Type="DateTime" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_fotonummer" Type="Int32" />
<asp:Parameter Name="original_inhoud" Type="String" />
<asp:Parameter Name="original_postdatum" Type="DateTime" />
<asp:Parameter Name="fotonummer" Type="Int32" />
<asp:Parameter Name="inhoud" Type="String" />
<asp:Parameter Name="postdatum" Type="DateTime" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="ddlFoto" Name="foto" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
</form>
</p>
</div>
</div>
我有一种感觉,其中涉及巨大的失败或其他什么,但我已经盯着它看了好几个小时,我就是找不到。