5

我有一个绑定到 ObjectDataSource 的 FormView。

* ObjectDataSource 定义(为简单起见省略了部分)*

<asp:ObjectDataSource 
    ID="odsHousehold" 
    runat="server"
    TypeName="BLL.Households"
    ConflictDetection="OverwriteChanges"
    UpdateMethod="UpdateHousehold" 
    >
    <UpdateParameters>
        <asp:Parameter Name="sName" Type="String" Direction="Input" />
        <asp:Parameter Name="sAddress" Type="String" Direction="Input" DefaultValue="" />
        <asp:Parameter Name="sCity" Type="String" Direction="Input" DefaultValue="" />
        <asp:Parameter Name="sState" Type="String" Direction="Input" DefaultValue="" />
        <asp:Parameter Name="sZip" Type="String" Direction="Input" DefaultValue="" />
    </UpdateParameters>
</asp:ObjectDataSource>

* FormView 定义(为简单起见,省略部分)*

   <asp:FormView 
    ID="fvHousehold"
    runat="server"
    DataKeyNames="HouseholdID"
    DataSourceID="odsHousehold"
    HorizontalAlign = "Left"
 >
<EditItemTemplate>
<asp:TextBox ID="txtHouseHoldName" runat="server" MaxLength="50" Width="100%" Text='<%# Bind("HouseholdName") %>'></asp:TextBox>
<asp:TextBox ID="txtAddress" runat="server" MaxLength="50" Width="100%" Text='<%# Bind("Address") %>'></asp:TextBox>
<asp:TextBox ID="txtCity" runat="server" MaxLength="50" Width="100%" Text='<%# Bind("City") %>'></asp:TextBox>
<asp:TextBox ID="txtState" runat="server" MaxLength="50" Width="100%" Text='<%# Bind("State") %>'></asp:TextBox>
<asp:TextBox ID="txtZip" runat="server" MaxLength="50" Width="100%" Text='<%# Bind("Zip") %>'></asp:TextBox>
 <asp:Button ID="btnUpdateHousehold" runat="server" Text="Update" CommandName="Update" />
</EditItemTemplate>
</asp:FormView>

我想知道:当单击更新按钮时,FormView 如何知道要使用哪个 EditTemplate TextBox 填充哪个 UpdateParameter?
例如,我没有在 FormView 中指示“txtAddress”填充 UpdateParameter“sAddress”,但 InputParameters[“sAddress”] 包含 txtAddress 的文本值。它怎么知道这样做?

有哪位大师能开导我吗?

太感谢了,

卡伦

4

3 回答 3

2

“当单击更新按钮时,FormView 如何知道要使用哪个 EditTemplate TextBox 填充哪个 UpdateParameter?”

我相信简单的答案是:它知道是因为您在 TextBox 控件中放置的 Bind 语句。例如 txtAddress 具有“Bind("Address")”,因此当调用更新时,它在 txtAddress 和参数“Address”之间建立了连接

于 2009-07-27T12:41:46.503 回答
1

Perhaps it is simply the order in which the TextBox controls are added to the EditItemTemplate? i.e. the order of the controls must match the order of the UpdateParameters...

Try swapping the position of txtHouseHoldName and txtAddress, does the address get passed into the sName parameter of your update method?

于 2009-04-20T06:13:14.283 回答
1

我的博客上有一篇文章详细讨论了 Bind() 如何在http://www.aarongoldenthal.com/post/2009/03/15/ASPNET-Databinding-Bind()-Method-Dissected.aspx 上工作。

于 2009-05-14T14:29:29.823 回答