tailieunhanh - Wrox’s ASP.NET 2.0 Visual Web Develope 2005 Express Edition Starter Kit phần 6

điều đó có nghĩa như là một hàng được thêm vào bảng này MenuItemID các sẽ được thiết lập tự động có sẵn bên cạnh tích cực số. Bảng đơn hàng hiển thị trong cửa sổ bên phải cũng cho thấy các kiểu dữ liệu cho mỗi cột, và chỉ ra rằng cột OrderID là khóa chính. Trong bảng này, có một cột OrderDate được quy định như kiểu datetime, | Displaying Nested and XML Data 15. If you run the page now you will see nothing in the Size and Price column. This is because the SqlDataSource in the ItemTemplate of the Gridview control cannot match any rows in the SizeAndPrice table the value of the @fkMenuItemID parameter is empty. To set the value you need to write some code that will execute as each row of the GridView is bound to its data source a row from the MenuItems table . Recalling how you learned in the previous chapter that controls raise events you will not be surprised to discover an event that provides just the opportunity you need. The GridView control raises a RowDataBound event after it has collected the data from the data source for each row and is ready to create the output. Go to the Solution Explorer window and open the code-behind page named . In the two drop-down lists at the top of the main VWD editing window select the GridView control GridView1 and the RowDataBound event as shown in Figure 5-17. Figure 5-17 Selecting the RowDataBound even 16. An outline of the event handler routine appears in the page see Figure 5-17 to which you can then add your own code see Figure 5-18 . The code you require is If Then Dim ds As SqlDataSource CType SqlDataSource2 SqlDataSource fkMenuItemID .DefaultValue .Value End If 141 Chapter 5 Figure 5-18 Outline of event handler routine The code used here looks complicated but has a simple task to accomplish. It first checks what type of row this is by looking at the RowType property of the row referenced through the arguments passed to the event handler it might be a data row a header row or a footer row . If it is a data row it will contain the SqlDataSource and Repeater controls. The code uses a method of the Row object named FindControl to get a reference to the SqlDataSource control in this row. Then it extracts the .

TỪ KHÓA LIÊN QUAN