/
Default.aspx.vb
53 lines (43 loc) · 1.96 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
Imports System
Imports System.Data
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports DevExpress.Spreadsheet
Imports DevExpress.Web.Office
Namespace ASPxSpreadsheetBinding
Public Partial Class [Default]
Inherits Page
Private SessionKey As String = "EditedDocumentID"
Protected Property EditedDocumentID As String
Get
Return If(CStr(Session(SessionKey)), String.Empty)
End Get
Set(ByVal value As String)
Session(SessionKey) = value
End Set
End Property
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack AndAlso Not IsCallback Then
If Not String.IsNullOrEmpty(EditedDocumentID) Then
Call DocumentManager.CloseDocument(DocumentManager.FindDocument(EditedDocumentID).DocumentId)
EditedDocumentID = String.Empty
End If
EditedDocumentID = Guid.NewGuid().ToString()
Dim view As DataView = CType(SqlDataSource1.Select(DataSourceSelectArguments.Empty), DataView)
Spreadsheet.Open(EditedDocumentID, DocumentFormat.Xlsx, Function() CType(view.Table.Rows(0)("DocBytes"), Byte()))
End If
End Sub
Protected Sub Spreadsheet_Saving(ByVal source As Object, ByVal e As DocumentSavingEventArgs)
' Save document with the Ribbon Save button
e.Handled = True
SqlDataSource1.Update()
End Sub
Protected Sub SaveButton_Click(ByVal sender As Object, ByVal e As EventArgs)
SqlDataSource1.Update()
End Sub
Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As SqlDataSourceCommandEventArgs)
e.Command.Parameters("@Id").Value = 1 ' First Row
e.Command.Parameters("@DocBytes").Value = Spreadsheet.SaveCopy(DocumentFormat.Xlsx)
End Sub
End Class
End Namespace