Page 167 - DCAP312_WEB_TECHNOLOGIES_II
P. 167

Unit 8: Creating More Advanced ASP.NET



                           <html>                                                                 Notes
                           <body>
                           <form runat= “server”>
                           <asp:ListBox id= “drop1” rows= “3” runat= “server”>
                           <asp:ListItem selected= “true”>Item 1</asp:ListItem>
                           <asp:ListItem>Item 2</asp:ListItem>
                           <asp:ListItem>Item 3</asp:ListItem>
                           <asp:ListItem>Item 4</asp:ListItem>
                           <asp:ListItem>Item 5</asp:ListItem>
                           <asp:ListItem>Item 6</asp:ListItem>
                           </asp:ListBox>
                           <asp:Button Text= “Submit” OnClick= “submit” runat= “server”/>
                           <p><asp:label id= “mess” runat= “server”/></p>

                           </form>
                           </body>
                           </html>



                      Write a program for code binding.

            8.4 Understanding Two-Way Data Binding


            One common example of two-way data binding is the DataSet/DataAdapter grouping. You
            can update the data in the DataSet, and then update the underlying data cause using the
            DataAdapter, or, if changes occur to the underlying data, you can refresh the DataSet using
            the Fill() method.

            With ASP.NET 2.0’s bi-directional data binding, you can eliminate the code required to update
            a data store by binding the data controls in your presentation layer to the data sources. Because
            the binding is bi-directional, when users modify the data in the controls the underlying data
            sources update when users post the web form back to the server. Typically, you have had to
            use code similar to the following to manage displayed data binding:
                     //Populate the data controls from a business object
                   txtCode.Text = emp.Code;
                   txtName.Text = emp.Name;
                     //Populate a business object from the data controls
                   emp.Code = txtCode.Text;
                   emp.Name = txtName.Text;
                     <%# Bind( “FieldName”) %>
            8.4.1 Sample Two-Way Data Binding Application

            To test the framework, you need to build an application that uses it. As a simple example, suppose
            you have an Employee entity, represented by an EmployeeDO class. This class contains three
            private fields and corresponding exposed public properties. It implements the IBusinessEntity
            interface and extends the Component class. IBusinessEntity is a base interface that all entities in
            this application extend, but this sample application deals exclusively with the Employee entity.


                                             LOVELY PROFESSIONAL UNIVERSITY                                   161
   162   163   164   165   166   167   168   169   170   171   172