Làm thế nào để sử dụng dữ liệu ràng buộc
khi bạn đã cấu hình một điều khiển nguồn dữ liệu, bạn có thể gắn nó vào một điều khiển biểu mẫu web để tự động hiển thị các dữ liệu lấy ra từ nguồn dữ liệu trên trang. Trong các chủ đề sau đây, bạn sẽ tìm hiểu làm thế nào để ràng buộc một danh sách kiểm soát với một nguồn dữ liệu và làm thế nào để ràng buộc các điều khiển xác định trong mẫu của một điều khiển như một điều khiển DataList.
Làm thế nào để ràng buộc một danh sách kiểm soát với một nguồn dữ liệu
hình 13-14 cho thấy làm thế nào để ràng buộc một danh sách kiểm soát với một nguồn dữ liệu. Để làm điều đó, bạn sử dụng ba thuộc tính trong bảng trong hình này. Các thuộc tính DataSourcelD cung cấp các ID của các nguồn dữ liệu. Các thuộc tính DataTextField cung cấp tên của các lĩnh vực nguồn dữ liệu được hiển thị trong danh sách. Và các thuộc tính DataValueField cung cấp tên của các lĩnh vực nguồn dữ liệu được trả về bởi thuộc tính SelectedValue khi người sử dụng chọn một mục từ danh sách.
Bạn có thể thiết lập các thuộc tính này bằng tay bằng cách sử dụng cửa sổ Properties hoặc bằng cách chỉnh sửa mã aspx. Hoặc, bạn có thể sử dụng Data Source Configuration Wizard hiển thị ở đầu của con số này để thiết lập các thuộc tính. Để làm điều đó, hiển thị menu thẻ thông minh cho danh sách và chọn Choose Data Source. Sau đó, sử dụng các điều khiển của wizard để thiết lập nguồn dữ liệu, lĩnh vực hiển thị, và lĩnh vực giá trị.
Đoạn mã ví dụ trong hình này cho thấy một danh sách thả xuống đó ràng buộc với một nguồn dữ liệu có tên SqlDataSourcel. Các trường có tên longname cung cấp các giá trị được hiển thị trong danh sách thả xuống, và các lĩnh vực tên CategorylD cung cấp giá trị đó được trả về bởi các thuộc tính SelectedValue khi người sử dụng chọn một mục từ danh sách.
đang được dịch, vui lòng đợi..