Blog Reader RSS LoveCherry 技术无极限 GEO MVP MS Project开源技术

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

 1Regarding on the GridView control's RowUpdating event problem, it is the 
 2expected behavior because when we do not associate GridView(or other 
 3ASP.NET 2.0 databound control) with DataSource control, it won'
 4automatically query and fill the parameters collection of the 
 5updating/deleting/ events. In such cases, we need to manually extract 
 6the field values from the Template control. Fortunately , ASP.NET 2.0 
 7provide some good helper functions which ease our work on extracting field 
 8values from template databound control's datafields. e.g. the 
 9BoundField.ExtractValuesFromCell method:
10
11#BoundField.ExtractValuesFromCell Method 
12http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
13d.extractvaluesfromcell.aspx
14
15So in our GridView's RowUpdating event, we can manually query the data 
16fields values (key , old values , new values) from the corresponding 
17cells. For example:
18
19=======================
20protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs 
21e)
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
posted @ 2008-05-16 14:18  大宋提刑官  阅读(1121)  评论(0编辑  收藏  举报