📄 defaultvb.aspx.vb
字号:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Telerik.QuickStart
Imports Telerik.QuickStart.Grid
Imports Telerik.WebControls
Namespace Telerik.GridExamplesVBNET.DataEditing.UserControlEditForm
Public Class DefaultVB
Inherits XhtmlPage
Protected WithEvents RadGrid1 As Telerik.WebControls.RadGrid
Private Sub RadGrid1_NeedDataSource(ByVal [source] As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
RadGrid1.DataSource = Me.Employees
End Sub
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Me.Session("Employees") = Nothing
End If
End Sub
Public ReadOnly Property Employees() As DataTable
Get
Dim obj As Object = Me.Session("Employees")
If (Not obj Is Nothing) Then
Return CType(obj, DataTable)
End If
Dim myDataTable As DataTable = New DataTable
myDataTable = DataSourceHelperVB.GetDataTable("SELECT * FROM Employees")
Me.Session("Employees") = myDataTable
Return myDataTable
End Get
End Property
Private Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
If Not IsPostBack Then
Me.RadGrid1.MasterTableView.Items(1).Edit = True
Me.RadGrid1.MasterTableView.Rebind()
End If
End Sub
Private Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As WebControls.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)
'Locate the changed row in the DataSource
Dim changedRows As DataRow() = Me.Employees.Select("EmployeeID = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("EmployeeID"))
If (Not changedRows.Length = 1) Then
e.Canceled = True
Return
End If
'Update new values
Dim newValues As Hashtable = New Hashtable
newValues("Country") = CType(MyUserControl.FindControl("TextBox7"), TextBox).Text
newValues("City") = CType(MyUserControl.FindControl("TextBox8"), TextBox).Text
newValues("Region") = CType(MyUserControl.FindControl("TextBox9"), TextBox).Text
newValues("HomePhone") = CType(MyUserControl.FindControl("TextBox10"), TextBox).Text
newValues("BirthDate") = CType(MyUserControl.FindControl("TextBox11"), TextBox).Text
newValues("TitleOfCourtesy") = CType(MyUserControl.FindControl("ddlTOC"), DropDownList).SelectedItem.Value
newValues("Notes") = CType(MyUserControl.FindControl("TextBox1"), TextBox).Text
newValues("Address") = CType(MyUserControl.FindControl("TextBox6"), TextBox).Text
newValues("FirstName") = CType(MyUserControl.FindControl("TextBox2"), TextBox).Text
newValues("LastName") = CType(MyUserControl.FindControl("TextBox3"), TextBox).Text
newValues("HireDate") = CType(MyUserControl.FindControl("Textbox5"), TextBox).Text
newValues("Title") = CType(MyUserControl.FindControl("TextBox4"), TextBox).Text
changedRows(0).BeginEdit()
Try
Dim entry As DictionaryEntry
For Each entry In newValues
changedRows(0)(CType(entry.Key, String)) = entry.Value
Next
changedRows(0).EndEdit()
Catch ex As Exception
changedRows(0).CancelEdit()
e.Canceled = True
End Try
End Sub
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -