在DataBound事件处理中编码确定数据的值


  本文标签:DataBound

  当FormView的标记完成后,下一步就是确定UnitsInStock的值是否小于等于10,这里和在DetailView中类似,先创建DataBound事件

  创建 DataBound 事件处理 

  图: 创建 DataBound 事件处理

  在事件中声明FormView的DataItem属性到ProductsRow实例中,确定UnitsInPrice的值并将对应的值用红色字体显示

  1. protected void LowStockedProductsInRed_DataBound(object sender, EventArgs e)  
  2.  
  3. {  
  4.  
  5.     // Get the ProductsRow object from the DataItem property...  
  6.  
  7.     Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)LowStockedProductsInRed.DataItem).Row;  
  8.  
  9.     if (!product.IsUnitsInStockNull() && product.UnitsInStock < = 10)  
  10.  
  11.     {  
  12.  
  13.         // TODO: Make the UnitsInStockLabel’s text red  
  14.  
  15.     }  
  16.  
  17. }  
  18.  

  这样就实现了在DataBound事件处理中编码确定数据的值  。