-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefault.aspx.vb
83 lines (70 loc) · 3.14 KB
/
Default.aspx.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Imports System
Imports System.Data
Imports DevExpress.Web
Namespace Solution
Public Partial Class [Default]
Inherits Web.UI.Page
Private Function GetTable() As DataTable
'You can store a DataTable in the session state
Dim table As DataTable = TryCast(Session("Table"), DataTable)
If table Is Nothing Then
table = New DataTable()
Dim colid As DataColumn = table.Columns.Add("ID", GetType(Integer))
Dim nameid As DataColumn = table.Columns.Add("Name", GetType(String))
table.PrimaryKey = New DataColumn() {colid}
colid.ReadOnly = True
For i As Integer = 0 To 23 - 1
Dim aRow As DataRow = table.NewRow()
aRow("ID") = i
aRow("Name") = String.Format("Name{0}", i)
table.Rows.Add(aRow)
Next
Session("Table") = table
End If
Return table
End Function
Public Function GetLastKey() As Integer
Dim table As DataTable = GetTable()
Dim max As Integer = Integer.MinValue
For Each row As DataRow In table.Rows
If Convert.ToInt32(row("ID")) > max Then max = Convert.ToInt32(row("ID"))
Next
Return max
End Function
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
grid.DataSource = GetTable()
grid.KeyFieldName = "ID"
grid.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Protected Sub grid_RowDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
Dim found As DataRow = table.Rows.Find(e.Keys(0))
table.Rows.Remove(found)
Session("Table") = table
e.Cancel = True
End Sub
Protected Sub grid_RowInserting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
table.Rows.Add(New Object() {e.NewValues("ID"), e.NewValues("Name")})
Session("Table") = table
e.Cancel = True
grid.CancelEdit()
End Sub
Protected Sub grid_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
Dim found As DataRow = table.Rows.Find(e.Keys(0))
found("Name") = e.NewValues("Name")
Session("Table") = table
e.Cancel = True
grid.CancelEdit()
End Sub
Protected Sub grid_InitNewRow(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataInitNewRowEventArgs)
e.NewValues("ID") = GetLastKey() + 1
End Sub
End Class
End Namespace