当 runat=server 用于表行时,FormView 中的双向数据绑定不起作用

发布于 2024-08-10 14:08:31 字数 3312 浏览 11 评论 0原文

我的 ObjectDataSource 设置如下:

<asp:ObjectDataSource ID="AccountDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetAccountByAccountID" TypeName="AccountBLL" InsertMethod="RegisterAccount" UpdateMethod="UpdateAccount">
    <SelectParameters>
        <asp:QueryStringParameter Name="iAccountID" QueryStringField="iAccountID" Type="Int32" />
    </SelectParameters>
    <InsertParameters>
        <asp:Parameter Name="sAccountname" Type="String" />
        <asp:Parameter Name="sPassword" Type="String" />
        <asp:Parameter Name="sConfirmPassword" Type="String" />
        <asp:Parameter Name="sEmailAddress" Type="String" />
        <asp:Parameter Name="sConfirmEmailAddress" Type="String" />
        <asp:Parameter Name="sDisplayName" Type="String" />
        <asp:Parameter Name="sRealName" Type="String" />
        <asp:Parameter Name="sSignature" Type="String" />
        <asp:Parameter Name="iTimezone" Type="Int32" />
        <asp:Parameter Name="iGuestAccountID" Type="Int32" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="sAccountname" Type="String" />
        <asp:Parameter Name="sPassword" Type="String" />
        <asp:Parameter Name="sRealName" Type="String" />
        <asp:Parameter Name="sDisplayName" Type="String" />
        <asp:Parameter Name="sEmailAddress" Type="String" />
        <asp:Parameter Name="sSignature" Type="String" />
        <asp:Parameter Name="bIsActive" Type="Boolean" />
        <asp:Parameter Name="iTimeZoneID" Type="Int32" />
        <asp:Parameter Name="iPrimaryGroup" Type="Int32" />
        <asp:Parameter Name="original_iAccountID" Type="Int32" />
    </UpdateParameters> </asp:ObjectDataSource>
<asp:ObjectDataSource ID="GroupDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetGroups" TypeName="GroupBLL">
</asp:ObjectDataSource>

在页面上的 FormView 中,在 EditItemTemplate 中我声明了以下内容:

<tr id="primaryGroupRow" runat="server">
  <td class="Fieldname">Primary Group:</td>
  <td><asp:DropDownList ID="iPrimaryGroupDropDownList" runat="server" DataSourceID="GroupDataSource" CssClass="PageText" 
DataTextField="sGroupName" DataValueField="iGroupID" SelectedValue='<%# Bind("iPrimaryGroup") %>'></asp:DropDownList></td>
</tr>

我遇到的问题是,当 AccountBLL 中的 UpdateAccount 方法触发时,iPrimaryGroup 字段始终设置为零。如果我检查 DropDownList 的情况,它似乎运行正常。由于某种原因,它只是没有将这一值传递回 UpdateAccount 函数。 DataSet 中未将其设置为 ReadOnly,并且在 DropDownList 中选择了正确的值。

几个小时前还运行得很好,突然就没有任何解释的原因停止工作了。我有另一个 DropDownList 控件,它几乎相同且工作正常。

我唯一能想到的是,我从 DropDownList 的不同 ObjectDataSource 中提取数据并尝试绑定该值并不高兴,但在另一个 DropDownList 中也发生了同样的事情,并且似乎正在工作适当地。

关于如何解决这个问题有什么想法吗?我已经多次重新启动 Visual Studio。我已经清除了缓存,重建了解决方案,比较了代码,并将 DropDownList 转换为标签,但没有骰子。

是否有地方可以强制进行双向绑定,或者可以在某个地方查看 UpdateParameters 和 EditItemTemplate 中的 FormView 控件之间的映射?我不需要将数据库中的字段重命名为 iGroupID 吗?

除了这一字段的值没有传递给函数之外,一切似乎都工作正常。任何帮助将不胜感激。

编辑:看起来在表行中,如果我取出 runat="server",它会再次开始工作。所以,我修改后的问题是:为什么?有办法解决这个问题吗?

I have an ObjectDataSource set up as follows:

<asp:ObjectDataSource ID="AccountDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetAccountByAccountID" TypeName="AccountBLL" InsertMethod="RegisterAccount" UpdateMethod="UpdateAccount">
    <SelectParameters>
        <asp:QueryStringParameter Name="iAccountID" QueryStringField="iAccountID" Type="Int32" />
    </SelectParameters>
    <InsertParameters>
        <asp:Parameter Name="sAccountname" Type="String" />
        <asp:Parameter Name="sPassword" Type="String" />
        <asp:Parameter Name="sConfirmPassword" Type="String" />
        <asp:Parameter Name="sEmailAddress" Type="String" />
        <asp:Parameter Name="sConfirmEmailAddress" Type="String" />
        <asp:Parameter Name="sDisplayName" Type="String" />
        <asp:Parameter Name="sRealName" Type="String" />
        <asp:Parameter Name="sSignature" Type="String" />
        <asp:Parameter Name="iTimezone" Type="Int32" />
        <asp:Parameter Name="iGuestAccountID" Type="Int32" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="sAccountname" Type="String" />
        <asp:Parameter Name="sPassword" Type="String" />
        <asp:Parameter Name="sRealName" Type="String" />
        <asp:Parameter Name="sDisplayName" Type="String" />
        <asp:Parameter Name="sEmailAddress" Type="String" />
        <asp:Parameter Name="sSignature" Type="String" />
        <asp:Parameter Name="bIsActive" Type="Boolean" />
        <asp:Parameter Name="iTimeZoneID" Type="Int32" />
        <asp:Parameter Name="iPrimaryGroup" Type="Int32" />
        <asp:Parameter Name="original_iAccountID" Type="Int32" />
    </UpdateParameters> </asp:ObjectDataSource>
<asp:ObjectDataSource ID="GroupDataSource" runat="server" OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetGroups" TypeName="GroupBLL">
</asp:ObjectDataSource>

Within a FormView on the page, in the EditItemTemplate I have declared the following:

<tr id="primaryGroupRow" runat="server">
  <td class="Fieldname">Primary Group:</td>
  <td><asp:DropDownList ID="iPrimaryGroupDropDownList" runat="server" DataSourceID="GroupDataSource" CssClass="PageText" 
DataTextField="sGroupName" DataValueField="iGroupID" SelectedValue='<%# Bind("iPrimaryGroup") %>'></asp:DropDownList></td>
</tr>

The problem I'm having is that when the UpdateAccount method in AccountBLL fires, the iPrimaryGroup field is always set to zero. If I examine the DropDownList for this, it appears to be functioning properly. For some reason, it's just not passing this one value back to the UpdateAccount function. It is not set to ReadOnly in the DataSet, and the correct value is selected in the DropDownList.

This was working fine a few hours ago, and it just suddenly stopped working for no explicable reason. I have another DropDownList control which is virtually identical that is working fine.

The only thing I can think of is that it's not happy that I'm pulling the data from a different ObjectDataSource for the DropDownList and attempting to Bind the value, but the same thing is happening in the other DropDownList and that one appears to be working properly.

Any ideas on how I might fix this? I've restarted Visual Studio several times. I've cleared my cache, I've rebuilt the solution, I've diff'd the code, and I've converted the DropDownList to a Label, but no dice.

Is there somewhere that I can force the two way binding to occur or a place I can look to see what the mappings are between the UpdateParameters and the FormView controls in the EditItemTemplate? I don't need to rename my field in the database to be iGroupID do I?

Everything appears to work fine except that the value for this one field isn't being passed to the function. Any help at all would be appreciated.

EDIT: It would appear that in the table row, if I take out runat="server", it starts working again. So, my revised question is: why? Is there a way around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文