开发者

Can’t get FormView values from ObjectDataSource on update

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 f开发者_JAVA技巧rom 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")%>' />

          &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>

      <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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜