【正文】
u should bind. Also, will work, where Customer is a business object that has a DataRow property. Here, you39。s displayed on the form merely so you can set properties on the wwDataBinder control itself. As an extender control, wwDataBinder contains a collection of DataBindingItems that hold the configuration values for each of the extended controls. The collection of items is maintained in the HTML markup and the control looks like this: ww:wwDataBinder ID=DataBinder runat=server OnValidateControl=DataBinder_ValidateControl DataBindingItems ww:wwDataBindingItem runat=server 11 ControlId=txtProductName BindingSource= BindingSourceMember=ProductName IsRequired=True ErrorMessageLocation=RedTextAndIconBelow /ww:wwDataBindingItem ... more DataBindingItems /DataBindingItems /ww:wwDataBinder The collection establishes the individual bindings that are applied by the DataBinder. While wwDataBinder extends existing controls, nothing is actually extended until you explicitly set properties on the DataBindingItem extender property of any given control on the form. In design mode, the extender exposes a DataBindingItem propertythis is for providing a mapping between a data item and a control property. Supported data items are data objects, such as DataRow fields. Alternatively, you can bind to an object and any simple property of an object that can be referenced through the Page object. It39。 2020 Properties editor (as shown in Figure 1). Figure 1 Extending Controls with Data Binding Functionality (Click the image for a larger view) The control sits on the form as a nondescript grey container (you can see this at the bottom of Figure 1), which isn39。s a problem with the formatting of an input fieldsay a numeric field that contains an alpha character or a DateTime value that sets a month of 22you get a pagelevel exception when you try to save the value. While you can trap the exception in pagelevel error handling, you can39。s CompanyName field to the TextBox39。ll demonstrate a flexible and intuitive approach that provides consistent behavior for data binding and unbinding, validation, error handling, and error display in formsbased Web interfaces. I39。通過這些鏈接可跳轉到發(fā)生錯誤的各個控件并使其突出顯示,從而有助于找到錯誤和修復錯誤。該控件還具有簡單的消息顯示方法(例如 ShowError 和 ShowMessage),它們顯示一行消息和一個圖標,為在頁面上顯示消息提供了一致的方式。該控件是可選的,但我喜歡用它來實現(xiàn)一致性。還可以使用 wwDataBinder 上的 ErrorIconUrl 屬性顯式替代該圖像。顯示也可以不顯示,您可以從整體上關閉 DataBinder 的警告圖標,也可以通過 ErrorMessageLocation 屬性更改各個 DataBindingItem 的位置和格式。另外,該控件會自動在頁面上提取任何驗證程序控件及其錯誤消息和控件 ID 并將它們合并到綁定錯誤機制中。這樣做可以向綁定了數(shù)據(jù)的控件分配任意錯誤消息,并可以使控件帶著錯誤圖標顯示,并出現(xiàn)在錯誤列表中。如果確定代 碼中 的某 個值 無效 ,則 可以通 過編 程方 式來 設置 BindingItem 的 BindingErrorMessage 以使其返回 false,以便讓聯(lián)編程序知道該 DataBindingItem 存在錯誤并需要顯示在錯誤列表上。 Dairy Products 錯誤將通過與 wwDataBinder 關聯(lián)的 ValidateControl 事件進行處理。如果有這樣的項被保留為空白,將自動生成綁定錯誤并將該錯誤添加到 BindingErrors 中。例如,圖 2 中顯示的 Reorder Expected 日期是一個無效日期,由于數(shù)據(jù)轉換失敗,因此控件將自動捕獲該錯誤。 6 圖 2 顯示綁定錯誤 (單擊該圖像獲得較大視圖 ) BindingError 可以由控件在綁定或取消綁定過程中自動生成,也可以在您的代碼中手動將其添加到 BindingErrors 集合中。默認情況下,發(fā)生錯誤的每個控件旁邊都會顯示錯誤圖標。當某個控件無法綁定或取消綁定時,該控件將在 BindingErrors 集合中生成 BindingError,但不會觸發(fā)異常。如果需要讓控件參與綁定錯誤管理,但不想將該控件綁定到某 個值,無方向綁定將非常適合這種情況。 數(shù)據(jù)綁定可以是單向、雙向或無方向的。 DataBindingItem 公開了與數(shù)據(jù)綁定過程關聯(lián)的其他屬性,如圖 1 所示。入站綁定通過調用 方 法 建 立 , 而 取 消 綁 定 則 通 過 調 用 方法來執(zhí)行。 BindingSource 的工作是在數(shù)據(jù)項或屬性與要將值綁定到的控件屬性之間建立綁定。 BindingSourceMember 始終是簡單類型,例如 int、 string、 DateTime、 bool 等。 BindingSource 是相對于頂級容器對象(通常為 Page 對象)表示的,但可以將頂級容器作為 DataBind 和 Unbind 方法的參數(shù)部分提供。如果 Page 上存在 DateTime RightNow 屬性,則綁定將如下所示: BindingSource: this BindingSourceMember: RightNow 任何 BindingSource 都隱式使用 this 或 me 來表示 Page 對象。 除 類型外,還可以綁定到 .NET 基類庫 (BCL) 中的業(yè)務實體 或類型。應首選 Public 屬性,因為中等信任中支持公共反射,而如果使用 Protected 屬性,反射將失敗。在將 DataTable 或 DataSet 用作 BindingSource 對象時, wwDataBinder 將假定將表的第一個 DataRow 或第一個表以及第一個 DataRow 作為 DataSet。 此外,還可以使用 ,其中 Customer 是具有 DataRow 屬性的業(yè)務對象。因此可以使用 。 假設需要綁定到 DataRow 對象。 BindingSource 包含兩個屬性: BindingSource(描述基對象的字符串屬性)和 BindingSo