tailieunhanh - Binding Data to a Web Forms DataList

[ Team LiB ] Recipe Binding Data to a Web Forms DataList Problem You need to bind the result set from a query to a DataList control. Solution Set the DataList's advanced properties as demonstrated by this solution. The schema of table TBL0703 that is used in the solution is shown in Table 7-2. Table 7-2. | Team LiB Recipe Binding Data to a Web Forms DataList Problem You need to bind the result set from a query to a DataList control. Solution Set the DataList s advanced properties as demonstrated by this solution. The schema of table TBL0703 that is used in the solution is shown in Table 7-2. Table 7-2. TBL0703 schema Column name Data type Length Allow nulls Id int 4 No IntField int 4 Yes StringField nvarchar 50 Yes The Web Forms page sample code defines the DataList control and the three templates SelectedItemTemplate ItemTemplate and EditItemTemplate which control the display of data for selected items unselected items and items being edited. The static Eval method of the DataBinder class is used to fill the field values in each template. specifies the container argument for the method which when used in a list in a template resolves to . The code for the Web Forms page is shown Example 7-5. Example 7-5. File asp DataList id dataList style Z-INDEX 102 LEFT 16px POSITION absolute TOP 56px runat server SelectedItemTemplate asp Button id editButton runat server Text Edit CommandName Edit asp Button B Id IntField StringField B SelectedItemTemplate ItemTemplate asp Button id selectButton runat server Text Select CommandName Select asp Button Id IntField StringField ItemTemplate EditItemTemplate asp Button id updateButton runat server Text Update CommandName Update asp Button asp Button id deleteButton runat server Text Delete CommandName Delete asp Button asp Button id cancelButton runat server Text Cancel CommandName Cancel asp Button BR asp Label id Label1 runat server ID asp Label asp TextBox id idTextBox runat server Width 96px ReadOnly True Text Id asp .