自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在ItemTemplate中格式化UnitsInStockLabel Label

開發(fā) 后端
本文講述了如何在FormView的ItemTemplate中格式化UnitsInStockLabel Label。

最后一步就是要在ItemTemplate中設(shè)置UnitsInStockLabel的樣式為紅色字體,在ItemTempelete中查找控件可以使用FindControl(“controlID”)方法

  1. WebControlType someName = (WebControlType)FormViewID.FindControl("controlID"); 

對于我們這個例子我們可以用如下代碼來查找該Label控件

  1. Label unitsInStock = (Label)LowStockedProductsInRed.FindControl("UnitsInStockLabel"); 

當我們找到這個控件時則可以修改其對應(yīng)的style屬性,在style.css中已經(jīng)有一個寫好的LowUnitsInStockEmphasis的cSS Class ,我們通過下面的代碼將cSS Class設(shè)置到對應(yīng)的屬性   

  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.             Label unitsInStock = (Label)LowStockedProductsInRed.FindControl("UnitsInStockLabel");  
  14.  
  15.    
  16.  
  17.             if (unitsInStock != null)  
  18.  
  19.             {  
  20.  
  21.                 unitsInStock.CssClass = "LowUnitsInStockEmphasis";  
  22.  
  23.             }  
  24.  
  25.         }  
  26.  
  27.     }  
  28.  

注意: 這種方式在FormView和GridView中也可以通過設(shè)置TemplateFields來達到同樣的效果,我們將在下一篇中討論TemplateFields

圖7顯示FormView在當UnitsInStock大于10的情況,圖8則顯示小于等于10的情況

在高于10的情況下,沒有值被格式化 

ItemTemplate: 在高于10的情況下,沒有值被格式化

小于等于10時,值用紅色字體顯示 

ItemTemplate:小于等于10時,值用紅色字體顯示

用GridView的 RowDataBound 事件自定義格式化

前面我們討論了在FormView和DetailsView中實現(xiàn)數(shù)據(jù)綁定的步驟,現(xiàn)在讓我們回顧下

1.DataBinding事件觸發(fā)

2.數(shù)據(jù)綁定到數(shù)據(jù)綁定控件

3.DataBound事件觸發(fā)

對于FormView和DetailsView有效因為只需要顯示一個數(shù)據(jù),而在GridView中,則要顯示所有數(shù)據(jù),相對于前面三個步驟,步驟二有些不同

在步驟二中,GridView 列出所有的數(shù)據(jù),對于某一個記錄將創(chuàng)建一個GridViewRow 實例并綁定,對于每個添加到GridView 中的 GridViewRow兩個事件將會觸發(fā):

· RowCreated – 當GridViewRow被創(chuàng)建時觸發(fā)

·RowDataBound – 當前記錄綁定到GridViewRow時觸發(fā).

對于GridView,請使用下面的步驟

1.DataBinding事件觸發(fā)

2.數(shù)據(jù)綁定到數(shù)據(jù)綁定控件

對于每一行數(shù)據(jù)..

a. 創(chuàng)建GridViewRow

b. 觸發(fā) RowCreated 事件

c.綁定數(shù)據(jù)到GridViewRow

d. 觸發(fā)RowDataBound事件

e. 添加GridViewRow到Rows 集合

DataBound事件觸發(fā)

為了自定義格式化GridView單獨記錄,我們需要為RowDataBound事件創(chuàng)建事件處理,讓我們添加一個GridView到CustomColors.aspx中,并顯示name, category, 和 price,用黃色背景高亮那些價格小于$10.00的產(chǎn)品

【編輯推薦】

  1. ASP.NET 2.0數(shù)據(jù)教程:SelectMethod屬性的使用
  2. ASP.NET 2.0數(shù)據(jù)教程:在業(yè)務(wù)邏輯層添加方法
  3. ASP.NET 2.0數(shù)據(jù)教程:為TableAdapter添加方法
  4. ASP.NET 2.0數(shù)據(jù)教程:使用一個硬編碼參數(shù)值
  5. ASP.NET 2.0數(shù)據(jù)教程:綁定到ObjectDataSource
責任編輯:book05 來源: 博客堂
相關(guān)推薦

2023-01-12 09:30:31

Linux命令行xml

2022-12-30 08:30:28

Linux命令行json

2009-07-27 16:46:07

DetailsView

2013-07-02 10:25:03

LinuxUSB設(shè)備

2020-11-03 10:21:33

MySQL

2009-08-03 14:25:59

C#日期格式化

2024-01-08 22:03:22

python代碼開發(fā)

2022-05-09 08:17:37

InstantJava字符

2011-03-07 15:01:42

MySQLXML數(shù)據(jù)

2024-12-09 08:10:00

Python字符串格式化

2010-07-29 11:12:30

Flex日期格式化

2009-08-03 16:24:05

C#格式化

2018-11-02 10:45:35

windowsU盤格式化

2010-07-16 16:00:08

Perl格式化輸出

2015-01-07 15:21:30

Android Stu代碼格式化

2010-07-16 15:44:57

Perl格式化輸出

2019-05-17 13:20:57

Black格式化工具Python

2010-07-16 15:23:34

Perl格式化輸出

2010-10-28 15:32:42

oracle日期格式化

2010-07-29 11:03:53

Flex代碼格式化
點贊
收藏

51CTO技術(shù)棧公眾號