You are on page 1of 1

http://forums.asp.net/p/1568749/3925760.aspx#3925760?Data+Controls-...

01. using System;
02. using System.Collections;
03. using System.Collections.Generic;
04. using System.Collections.Specialized;
05. using System.Configuration;
06. using System.Data;
07. using System.Data.SqlClient;
08. using System.Web.UI;
09. using System.Web.UI.WebControls;
10.
11. public partial class DetailsView_CRUDWithADO : System.Web.UI.Page
12. {
13. private IDictionary<string, object> GetValues(DetailsView dv)
14. {
15. IOrderedDictionary dictionary = new OrderedDictionary();
16.
17. foreach (DetailsViewRow row in dv.Rows)
18. {
19. foreach (Control control in row.Controls)
20. {
21. DataControlFieldCell cell = control as DataControlFieldCell;
22.
23. if ((cell != null) && cell.Visible)
24. {
25. cell.ContainingField.ExtractValuesFromCell(
26. dictionary,
27. cell,
28. row.RowState,
29. true);
30. }
31. }
32. }
33.
34. IDictionary<string, object> values = new Dictionary<string, object>();
35.
36. foreach (DictionaryEntry de in dictionary)
37. {
38. values[de.Key.ToString()] = de.Value;
39. }
40.
41. return values;
42. }
43.
44. private void GetData()
45. {
46. using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConn
47. using (SqlCommand cmd = new SqlCommand("SELECT * FROM [Shippers]", conn))
48. using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
49. {
50. try
51. {
52. conn.Open();
53.
54. DataTable dt = new DataTable();
55. adapter.Fill(dt);
56.
57. dvShippers.DataSource = dt;
58. dvShippers.DataBind();
59. }
60. catch { }
61. }
62. }
63.
64. protected void Page_Load(object sender, EventArgs e)
65. {

1 of 1 11/2/2010 1:55 PM