john dyer
dallas theological seminaryseptember 2004
applies to:
microsoft visual studio 2005 and previous versions asp.net 1.1 c# programming language visual basic programming languagesummary: use reflection to bind your business objects to asp.net web forms with a single line of code, resulting in decreased complexity and fewer errors. (12 printed pages)
download the msdformbinding.msi sample file.
contentsintroduction
simplifying and shortening form code getting started: retrieving a list of properties from reflection binding object property values to controls setting values of unknown controls with known properties reversing the process: bindcontrolstoobject performance and extending the formbinding scheme conclusion introductionone of the most common tasks web developers do over and over is to build a simple form that updates a database table. we create a list page that displays the records in a table and a form page with appropriate form controls for each database field. many developers also use business objects that represent their database tables to organize their code into a multitiered design. if the database table (documents) is represented by a business object (document), many of our forms look something like the code below:
<script runat="server"> protected void page_load(object src, eventargs e) { if (!ispostback) { document document = documents.getdocument(request.querystring["documentid"]); title.text = document.title; active.checked = document.active; createddate.text = document.createddate.tostring(); authorid.findbyvalue(document.authorid.tostring()).selected = true; // ... and so on htmlbody.text = document.htmlbody; } } protected void savebutton_click(object src, eventargs e) { document document = documents.getdocument(request.querystring["documentid"]); document.title = title.text; document.active = active.checked; document.createddate = convert.todatetime(createddate.text); document.authorid = convert.toint32(authorid.selecteditem.value); // ... and so on document.htmlbody = htmlbody.text; documents.update(document); } </script> simplifying and shortening form code ... 下一页