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

在RowDataBound的事件處理中編碼確定數據對應的值

開發(fā) 后端
本文簡單介紹了如何在RowDataBound的事件處理中編碼確定數據對應的值。

當ProductsDataTable綁定到GridView,GridView將會產生若干個ProductsRow。GridViewRow的DataItem屬性將會生成一個實際的ProductRow。在GridView的 RowDataBound事件發(fā)生之后,為了確定UnitsInStock的值,我們需要創(chuàng)建RowDataBound的事件處理,在其中我們可以確定UnitsInStock的值并做相應的格式化

EventHandler的創(chuàng)建過程和前面兩個一樣

創(chuàng)建GridView的RowDataBound事件的事件處理 

RowDataBound: 創(chuàng)建GridView的RowDataBound事件的事件處理

在后臺代碼里將會自動生成如下代碼

  1. protected void HighlightCheapProducts_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.  
  3. {  
  4.  
  5. }  
  6.  

當RowDataBound事件觸發(fā),第二個參數GridViewRowEventArgs中包含了對GridViewRow的引用,我們用如下的代碼來訪問GridViewRow中的ProductsRow   

  1. protected void HighlightCheapProducts_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.  
  3.     {        // Get the ProductsRow object from the DataItem property...  
  4.  
  5.         Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)e.Row.DataItem).Row;  
  6.  
  7.         if (!product.IsUnitPriceNull() && product.UnitPrice <  10m)  
  8.  
  9.         {  
  10.  
  11.             // TODO: Highlight the row yellow...  
  12.  
  13.        }  
  14.  
  15.     }  
  16.  

當運用RowDataBound事件處理時,GridView由各種類型不同的行組成,而事件發(fā)生針對所有的行類型, GridViewRow的類型可以由RowType屬性決定,可以是以下類型中的一種

·DataRow – GridView的DataSource中的一條記錄

·EmptyDataRow – GridView的DataSource顯示出來的某一行為空

·Footer – 底部行; 顯示由GridView的ShowFooter屬性決定

·Header – 頭部行; 顯示由GridView的ShowHeader屬性決定

·Pager – GridView的分頁,這一行顯示分頁的標記

·Separator – 對于GridView不可用,但是對于DataList和Reapter的RowType屬性卻很有用,我們將在將來的文章中討論他們

當上面四種(DataRow, Pager Rows Footer, Header)都不合適對應值時,將返回一個空的數據項, 所以我們需要在代碼中檢查GridViewRow的RowType屬性來確定:

  1. protected void HighlightCheapProducts_RowDataBound(object sender, GridViewRowEventArgs e)  
  2.  
  3. {  
  4.  
  5.         // Make sure we are working with a DataRow  
  6.  
  7.         if (e.Row.RowType == DataControlRowType.DataRow)  
  8.  
  9.         {  
  10.  
  11.             // Get the ProductsRow object from the DataItem property...  
  12.  
  13.             Northwind.ProductsRow product = (Northwind.ProductsRow)((System.Data.DataRowView)e.Row.DataItem).Row;  
  14.  
  15.             if (!product.IsUnitPriceNull() && product.UnitPrice <  10m)  
  16.  
  17.             {  
  18.  
  19.                 // TODO: Highlight row yellow...  
  20.  
  21.             }  
  22.  
  23.         }  
  24.  
  25. }  
  26.  

【編輯推薦】

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

2009-07-27 16:56:05

DataBound

2009-07-27 16:42:16

DataBound

2016-01-22 11:05:07

2010-03-23 14:34:44

Python vim檢

2009-06-14 17:53:25

ibmdwWebSphere

2015-07-20 11:12:43

數據中心數據中心建設

2013-05-15 15:30:02

數據中心綜合布線

2023-12-07 19:00:25

數據科學機器學習數據可視化

2017-03-14 13:51:23

AndroidView事件分發(fā)和處理

2017-12-27 14:22:07

數據中心負載成本

2016-04-29 10:02:39

2011-06-16 14:23:43

JavaScript空事件處理程序

2021-02-06 10:27:45

C#函數參數

2023-10-04 00:01:00

sizeofC 語言

2009-07-28 08:24:16

GridView綁定數

2010-04-28 18:25:51

Oracle數據庫

2011-04-01 14:14:42

SQL Server空值

2010-05-31 15:23:02

MySQL數據庫NUL

2009-06-10 15:27:08

netbeans 編碼亂碼

2020-09-25 11:10:51

運維故障排查監(jiān)控
點贊
收藏

51CTO技術棧公眾號