Browse DevX
Sign up for e-mail newsletters from DevX


Implementing Two-Way Control Binding for Web Forms : Page 2

ASP.NET's native data binding provides only one-way data binding. With a little bit of effort, it's possible to extend the native functionality and provide flexible two-way data binding and a few other simple enhancements that drastically reduce the amount of code you have to write for binding data to controls.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

How Things Work Now
Let me give you an example to put the current process into perspective. Assume that I have a business form and want to display and edit some customer information. I use my business object to load up a DataSetwith data from a Load() method that internally populates a DataSetand DataRowmember (you could also do this manually, of course). I now have a DataSet that I can bind to the various controls. This is easily done by using the control's data-binding options in the property sheet or by manually assigning the value using the ASP.NET data binding scripting syntax (yes, another variation of <% %> syntax using <%# %>). What's interesting is that the binding syntax is not property-based but generates a chunk of ASP.NET script code that gets embedded into the HTML. The following code binds to the Company field of my DataRow, for example:

<asp:TextBox id = "txtCompany" runat = "server" Width = "285px" Text = '<%# Customer.DataRow["company"] %>'> </asp:TextBox>

You can enter that expression manually into the ASP.NET HTML document or you can use the builder that generates this expression automatically, as shown in Figure 1.

This syntax is not exactly intuitive and requires the ASP.NET script parser to parse the string first before ever assigning the data binding expression to be evaluated.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date