tailieunhanh - Binding Complex Data to Web Forms Controls

[ Team LiB ] Recipe Binding Complex Data to Web Forms Controls Problem You want to bind multiple columns in multiple records to an control. Solution Set the control's advanced properties (see Table 7-1) before calling DataBind( ). | Team LiB Recipe Binding Complex Data to Web Forms Controls Problem You want to bind multiple columns in multiple records to an control. Solution Set the control s advanced properties see Table 7-1 before calling DataBind . The Web Forms page sample code defines the ListBox that is populated with data by the code-behind page logic. The code for the Web Forms page is shown in Example 7-3. Example 7-3. File asp ListBox id categoriesListBox style Z-INDEX 102 LEFT 88px POSITION absolute TOP 64px runat server Width 184px Height 216px asp ListBox The code-behind contains one event handler Fills a DataTable with the CategorylD and CategoryName from the Categories table in the Northwind sample database. The ListBox server control is bound to the DataTable. The C code for the code-behind is shown in Example 7-4. Example 7-4. File Namespaces variables and constants using System using using using . . . private void Page_Load object sender e Create a DataAdapter and use it to retrieve ID and Name for all categories. String sqlText SELECT CategorylD CategoryName FROM Categories ORDER BY CategoryName SqlDataAdapter da new SqlDataAdapter sqlText DataConnectString DataTable table new DataTable Categories table Bind the table to the list box control. CategorylD CategoryName Discussion Complex data binding describes binding a multi-record control to multiple records in a data source. The DataGrid DataList and ListBox controls are examples of controls that support complex data binding. Each control that supports complex data binding exposes a set of properties which are slightly different for each control that control the binding. These properties are described in .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.