GridView, DataSource, RowUpdating, e.OldValues and e.NewValues collections

 1 Regarding on the GridView control ' s RowUpdating event problem, it is the 
 2 expected behavior because when we  do  not associate GridView(or other 
 3 ASP.NET  2.0  databound control) with DataSource control, it won '
 4 automatically query and fill the parameters collection of the 
 5 updating / deleting /  events. In such cases, we need to manually extract 
 6 the field values from the Template control. Fortunately , ASP.NET  2.0  
 7 provide some good helper functions which ease our work on extracting field 
 8 values from template databound control ' s datafields. e.g. the 
 9 BoundField.ExtractValuesFromCell method:
10
11 #BoundField.ExtractValuesFromCell Method 
12 http: // msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
13 d.extractvaluesfromcell.aspx
14
15 So  in  our GridView ' s RowUpdating event, we can manually query the data 
16 fields values (key , old values ,  new  values) from the corresponding 
17 cells. For example:
18
19 =======================
20 protected   void  GridView1_RowUpdating( object  sender, GridViewUpdateEventArgs 
21 e)
22      {
23       
24
25        DataControlFieldCell cell = GridView1.Rows[e.RowIndex].Cells[0as 
26DataControlFieldCell;
27      
28
29        GridView1.Columns[0].ExtractValuesFromCell(
30            e.Keys,
31            cell,
32            DataControlRowState.Normal,
33            true);
34
35
36        cell = GridView1.Rows[e.RowIndex].Cells[1as DataControlFieldCell;
37
38
39        GridView1.Columns[1].ExtractValuesFromCell(
40            e.NewValues,
41            cell,
42            DataControlRowState.Edit,
43            true);
44
45
46        foreach (string key in e.Keys.Keys)
47        {
48            response.write("<br/>" + key + "" + e.Keys[key]);
49        }

50
51        foreach (string key in e.NewValues.Keys)
52        {
53            response.write("<br/>" + key + "" + e.NewValues[key]);
54        }

55
链接地址: http://www.developersdex.com/asp/message.asp?p=2908&ID=%3CuvU%24WBARGHA.3052%40TK2MSFTNGP09.phx.gbl%3E

转载于:https://www.cnblogs.com/onlyendure/archive/2008/05/16/1200553.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值