Stand back, I know regular expressions! (Part 2)

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.

image

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.


Feedback

No comments posted yet.


Post a comment





 

Please add 7 and 7 and type the answer here: