Page 53 - DCAP312_WEB_TECHNOLOGIES_II
P. 53

Unit 3: Server Controls Basic



            Insert, Update and Delete                                                             Notes
            To insert data into List View, we need to add a tag in List View named InsertItemTemplate.
            Add to add inserted code, add code in Item Command.
                   HTML Code
                   <InsertItemTemplate>
                   <tr runat= “server”>
                   <td></td>
                   <td>
                   <asp:TextBox ID= “txtFname” runat= “server”
                     Text=’<%#Eval(“FirstName”) %>’ Width= “100px”>First Name</
                   asp:TextBox>
                   <asp:TextBox ID= “txtLname” runat= “server”
                     Text=‘<%#Eval(“LastName”)  %>’Width= “100px”>Last Name</
                   asp:TextBox>
                   </td>
                   <td><asp:TextBox ID= “txtCtype” runat= “server”
                     Text=‘<%#Eval(“ContactType”)%>’Width=“100px”>Contact  Type</
                   asp:TextBox></td>
                   <td><asp:Button ID= “InsertButton” runat= “server”
                    CommandName= “Insert” Text= “Insert” /></td>
                   </tr>
                   </InsertItemTemplate>
            CS Code
            In the CS file, insert this code in Item Command:

                   if (e.CommandName == “Insert”)
                   {
                   TextBox txtFname = (TextBox)e.Item.FindControl( “txtFname”);
                   TextBox txtLname = (TextBox)e.Item.FindControl( “txtLname”);
                   TextBox txtCtype = (TextBox)e.Item.FindControl( “txtCtype”);
                   string insertCommand = “Insert into [Contacts]
                   ([FirstName],[LastName],[ContactType]) Values(““ + txtFname.Text + ““, ““
                   + txtLname.Text + ““, ““ + txtCtype.Text + ““);”;
                    SqlDataSource1.InsertCommand = insertCommand;
                   }
            In the same way, code for Update and Delete will be done using EditItemTemlpate. Please check
            the attached source files to get the complete code.
            3.2.1 Properties of Data Binding

            The following properties and schemes are used when required the RadTreeView to a data spring:
               •  Data Source property: Set to an instance of our data source. This is compulsory when
                 required the RadTreeView at runtime.
               •  DataSourceID property: Set to the ID of our data source. This is mandatory when binding
                 the RadTreeView declaratively.



                                             LOVELY PROFESSIONAL UNIVERSITY                                    47
   48   49   50   51   52   53   54   55   56   57   58