Now that we’ve got an asp.net DetailsView control with fields from a SubSonic ObjectDataSource and we’ve set the header text, it’s time to work on the code-behind code needed to update the object.
The DetailsView template has the following fields:
<asp:BoundField DataField="DirectMarketing" HeaderText="Direct Marketing"
SortExpression="DirectMarketing" />
<asp:BoundField DataField="AffiliateMarketing" HeaderText="Affiliate Marketing"
SortExpression="AffiliateMarketing" />
[... and lots of other fields]
We’ll use Visual Studio 2008’s find and replace to generate the update code.
Find what:
\<.#DataField="{.#}"([^\>]|\n)#\>
Replace with:
plan.\1 = (string) values["\1"] ?? "";
The results:
plan.DirectMarketing = (string) values["DirectMarketing"] ?? "";
plan.AffiliateMarketing = (string) values["AffiliateMarketing"] ?? "";
[... and lots more]
This reduces the amount of duplicate effort required to update the object based on the BoundField’s values.
![Wait, forgot to escape a space. Wheeeeee[taptaptap]eeeeee. Wait, forgot to escape a space. Wheeeeee[taptaptap]eeeeee.](http://imgs.xkcd.com/comics/regular_expressions.png)