Reputation: 53
I am using Framework 4.5 and decided to take advantage of some its improvements.. Let's say I have the following control inside FormView:
<asp:TextBox ID="EventNumberTextBox" runat="server" Text='<%# Item.Event_Num %>' />
In my UpdateMethod I make the following:
public void UpdateModelFromView(int? ID)
{
var modelView = new AlertMessageController().LoadById(ID);
var updateSuccess = TryUpdateModel(modelView);
if (updateSuccess)
{
new AlertMessageController().Save(modelView);
RedirectToViewPage();
}
}
The problem is that although the Form collection does contain all the changes I made - in the given case I have set Event_Num to some value - the changes are not reflected to modelView. In other words, any changes I make into FormView controls, are ignored and the model is saved as is after loading...
Upvotes: 1
Views: 1774
Reputation: 1839
Item is for one-way data binding only. For two-way data binding you should use BindItem, i.e., BindItem.Event_Num.
Upvotes: 3
Reputation: 1263
Unfortunately, their example is quite narrow. I have downloaded it to analyze. They do not demonstrate FormView update methods, only grids, so I have no idea about IDs and NAMEs of FormView controls. I thought that bound values should be enough to set correspondence to actual properties for update (i.e. Item.Event_Num). There is one more weird thing: when I click on TryUpdateModel method - it takes me to UserControl, but it does not show this method's description! But I do have FrameWork 4.5 installed and my documentation is taken from ONLINE source...
Upvotes: 0
Reputation: 1154
Anik, I believe that the form field name needs to match the property name.
Upvotes: 0