更新时无法从 ObjectDataSource 获取 FormView 值

发布于 2024-09-07 18:16:20 字数 2772 浏览 2 评论 0原文

使用 .NET 2.0,我有一个 FormView,其中的字段绑定到 ObjectDataSource (ODS)。这些字段以正确的值开始,也就是说,当调用 ODS 的 SelectMethod 时,它们来自 Person 对象,但是在进行更改并调用 ODS 的 UpdateMethod 后,我无法从字段中获取这些新值或任何值从更新调用堆栈中的任何位置。我的代码如下所示:

    <div id="personInfo"><asp:FormView ID="fvwPerson" runat="server" DataSourceID="srcPerson" DefaultMode="Edit">

    <EditItemTemplate>

          <table border="0" width="100%" style="font-weight:bold">

...

        <td align="right">

          First Name:

        </td>

        <td>

          <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName")%>' />

          &nbsp;&nbsp;&nbsp;&nbsp;Middle Name: &nbsp;<asp:TextBox ID="txtMiddleName" runat="server"

            Text='<%# Bind("MiddleName")%>' />

          &nbsp;&nbsp;&nbsp;&nbsp;Last Name: &nbsp;

          <asp:TextBox ID="TextBox5" runat="server"

            Text='<%# Bind("LastName")%>' />

……

        </EditItemTemplate>

    </asp:FormView>

  </div>

SavePerson

      <asp:ObjectDataSource ID="srcPerson" runat="server" SelectMethod="GetPersonInfo" UpdateMethod="SavePersonInfo"

        TypeName="BLL.Person">

        <SelectParameters>

          <asp:SessionParameter Name="personID" SessionField="personid" DefaultValue="0" />

        </SelectParameters>

        <UpdateParameters>

          <asp:Parameter Name="firstName" Type="String" Direction="Input" DefaultValue="Fail 1!" />

          <asp:Parameter Name="middleName" Type="String" Direction="Input" DefaultValue="Fail 2!" />

          <asp:Parameter Name="lastName" Type="String" Direction="Input" DefaultValue="Fail 3!" />

        </UpdateParameters>

      </asp:ObjectDataSource>

中,参数值分别为“Fail 1!”、“Fail 2!”、“Fail 3!”。我还尝试使用 FormParameters,得到相同的结果:

          <asp:FormParameter Name="firstName" FormField="txtFirstName" Type="String" Direction="Input" DefaultValue="Fail 1!" />

          <asp:FormParameter Name="middleName" FormField="txtMiddleName" Type="String" Direction="Input" DefaultValue="Fail 2!" />

          <asp:FormParameter Name="lastName" FormField="txtLastName" Type="String" Direction="Input" DefaultValue="Fail 3!" />

我还尝试在字段名称前面加上“fvwPerson”。我还尝试处理 ODS 的更新事件,但 e.InputParameters 全部以“失败”开头。我真的以为我遵循了所有正确的例子,我做错了什么?请让我不必调用 DirectCast(fvwPerson.FindControl("fieldName"), TextBox).Text 38 次!谢谢...

编辑 7/6/10:我可能应该提到我只有用于编辑的项目模板,没有用于查看的项目模板(我不觉得我应该复制所有这些控件),并且作为 FormView 标签表示,编辑是其默认模式。这是我的问题的潜在根源吗?

Working with .NET 2.0, I have a FormView with fields bound to an ObjectDataSource (ODS). Those fields start out with the correct values—that is, they come from the Person object when the ODS’s SelectMethod is called—but after making changes and calling the ODS’s UpdateMethod, I can’t get these new—or any—values from the fields from anywhere in the update’s call stack. My code looks like this:

    <div id="personInfo"><asp:FormView ID="fvwPerson" runat="server" DataSourceID="srcPerson" DefaultMode="Edit">

    <EditItemTemplate>

          <table border="0" width="100%" style="font-weight:bold">

        <td align="right">

          First Name:

        </td>

        <td>

          <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName")%>' />

              Middle Name:  <asp:TextBox ID="txtMiddleName" runat="server"

            Text='<%# Bind("MiddleName")%>' />

              Last Name:  

          <asp:TextBox ID="TextBox5" runat="server"

            Text='<%# Bind("LastName")%>' />

        </EditItemTemplate>

    </asp:FormView>

  </div>

      <asp:ObjectDataSource ID="srcPerson" runat="server" SelectMethod="GetPersonInfo" UpdateMethod="SavePersonInfo"

        TypeName="BLL.Person">

        <SelectParameters>

          <asp:SessionParameter Name="personID" SessionField="personid" DefaultValue="0" />

        </SelectParameters>

        <UpdateParameters>

          <asp:Parameter Name="firstName" Type="String" Direction="Input" DefaultValue="Fail 1!" />

          <asp:Parameter Name="middleName" Type="String" Direction="Input" DefaultValue="Fail 2!" />

          <asp:Parameter Name="lastName" Type="String" Direction="Input" DefaultValue="Fail 3!" />

        </UpdateParameters>

      </asp:ObjectDataSource>

In SavePerson, the parameter values are “Fail 1!”, “Fail 2!”, and “Fail 3!”, respectively. I’ve also tried using FormParameters, with the same results:

          <asp:FormParameter Name="firstName" FormField="txtFirstName" Type="String" Direction="Input" DefaultValue="Fail 1!" />

          <asp:FormParameter Name="middleName" FormField="txtMiddleName" Type="String" Direction="Input" DefaultValue="Fail 2!" />

          <asp:FormParameter Name="lastName" FormField="txtLastName" Type="String" Direction="Input" DefaultValue="Fail 3!" />

I also tried preceding the field names with "fvwPerson.". I also tried handling the Updating event for the ODS but e.InputParameters all began with "Fail". I really thought I was following all the right examples, what am I doing wrong? Please save me from having to call DirectCast(fvwPerson.FindControl("fieldName"), TextBox).Text 38 times! Thank you…

EDIT 7/6/10: I probably should have mentioned that I have only the item template for editing, not one for viewing (I didn't feel I should have to duplicate all those controls), and as the FormView tag indicates, edit is its default mode. Is that a potential source of my problem?

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

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

发布评论

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