FormView EditTemplate 如何在后台更新 ObjectDataSource UpdateParameters 中的值?

发布于 2024-07-17 03:08:24 字数 2241 浏览 7 评论 0原文

我有一个绑定到 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 的文本值。 它怎么知道要这样做?

有哪位大师可以赐教一下吗?

非常感谢你,

卡伦

I have a FormView bound to an ObjectDataSource.

* ObjectDataSource definition (omitted portion of it for simplicity)*

<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 definition (omitted portion of it for simplicity) *

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

I'd like to know: how does the FormView know which UpdateParameter to populate with which EditTemplate TextBox when the Update button is clicked?
For instance, I haven't instructed "txtAddress" in the FormView to populate the UpdateParameter "sAddress" but InputParameters["sAddress"] contains the Text value of txtAddress. How does it know to do that?


Could any guru enlighten me?

Thank you so much,

Cullen

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

静若繁花 2024-07-24 03:08:24

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

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

"how does the FormView know which UpdateParameter to populate with which EditTemplate TextBox when the Update button is clicked?"

I believe the simple answer is: it knows because of the Bind statements you put in the TextBox controls. E.g. txtAddress has "Bind("Address")" so when the update is called, it has a connection between txtAddress and parameter "Address"

微凉 2024-07-24 03:08:24

也许这只是将 TextBox 控件添加到 EditItemTemplate 的顺序? 即控件的顺序必须与 UpdateParameters 的顺序匹配...

尝试交换 txtHouseHoldName 和 txtAddress 的位置,该地址是否传递到更新方法的 sName 参数中?

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?

谁对谁错谁最难过 2024-07-24 03:08:24

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

I have a post on my blog with a detailed discussion of how Bind() works at http://www.aarongoldenthal.com/post/2009/03/15/ASPNET-Databinding-Bind()-Method-Dissected.aspx
.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文