DataGrid的两个事件

DataGrid.ItemDataBound 事件:
当项被数据绑定到 DataGrid 控件后,将引发 ItemDataBound 事件。此事件为您提供了在客户端显示数据项之前访问该数据项的最后机会。当引发此事件后,该数据项将被设为空,并且不再可用。
例:
ContractedBlock.gif ExpandedBlockStart.gif 事件示例
None.gif        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                e.Item.Attributes.Add(
"onclick","__doPostBack('"+((LinkButton)e.Item.Cells[4].Controls[0]).ClientID.Replace("__","$_")+"','')");
InBlock.gif                
this.Label1.Text+="***"+"__doPostBack('"+((LinkButton)e.Item.Cells[4].Controls[0]).ClientID.Replace("__","$_")+"','')";
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if(e.Item.ItemType==ListItemType.EditItem)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                e.Item.Attributes.Add(
"ondblclick","__doPostBack('"+((LinkButton)e.Item.Cells[5].Controls[0]).ClientID.Replace("__","$_")+"','')");
InBlock.gif                
for(int i=1;i<4;i++)
InBlock.gif                    ((TextBox)e.Item.Cells[i].Controls[
0]).Attributes.Add("onmouseover","this.select()");
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
         void Item_Bound(Object sender, DataGridItemEventArgs e) 
ExpandedBlockStart.gifContractedBlock.gif       
dot.gif{
InBlock.gif 
InBlock.gif         
// Use the ItemDataBound event to customize the DataGrid control. 
InBlock.gif         
// The ItemDataBound event allows you to access the data before 
InBlock.gif         
// the item is displayed in the control. In this example, the 
InBlock.gif         
// ItemDataBound event is used to format the items in the 
InBlock.gif         
// CurrencyColumn in currency format.
InBlock.gif
         if((e.Item.ItemType == ListItemType.Item) || 
InBlock.gif             (e.Item.ItemType 
== ListItemType.AlternatingItem))
ExpandedSubBlockStart.gifContractedSubBlock.gif         
dot.gif
InBlock.gif            
// Retrieve the text of the CurrencyColumn from the DataGridItem
InBlock.gif            
// and convert the value to a Double.
InBlock.gif
            Double Price = Convert.ToDouble(e.Item.Cells[2].Text);
InBlock.gif
InBlock.gif            
// Format the value as currency and redisplay it in the DataGrid.
InBlock.gif
            e.Item.Cells[2].Text = Price.ToString("c");        
ExpandedSubBlockEnd.gif         }
          
ExpandedBlockEnd.gif      }

DataGrid.ItemCreated 事件:
当创建 DataGrid 控件中的项时(不论是在往返行程中还是在将数据绑定到控件时),都会引发 ItemCreated 事件。 ItemCreated 事件通常用于控制 DataGrid 控件中行的内容和外观。

转载于:https://www.cnblogs.com/newblog/archive/2006/04/29/388699.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值