Reputation: 2105
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
Upvotes: 5
Views: 13102
Reputation:
"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"
Upvotes: 2
Reputation:
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 .
Upvotes: 1
Reputation: 271
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?
Upvotes: 1